Java & C++ in Xcode - Question

Discussion in 'Mac Programming' started by Koreos, Feb 1, 2009.

  1. macrumors member

    I know it isn't practical to use Xcode for Java & C++, but I only need it to get by for the school projects (silly, one-file classes). And I would like to avoid having to install different IDEs.

    My question is, how do I use Xcode without a project? (using it with a single .java or .cpp file)
    I've tried opening the .java file, but all the build, run, debug, etc options are greyed out.

    Thank you.
  2. macrumors 6502a

    The short answer to your question is you don't use Xcode without a project. Create the project sets everything up for compiling and linking and builds.

    I created a Java Application project in Xcode the other day, just to see what I would get, and I was very surprised to find tons of crap I did not need.

    So, I went back to using an editor (I use TextWrangler) and the command line in Terminal. It works. However, I've gotten myself spoiled on Windows using Eclipse for the last couple weeks. It's like having your own little teaching assistant inside the computer, help you along and pointing out everything you need to know as you go.

    I use XCode a lot for C++ projects. It's an all-in-one stop for doc, editing, code completion and interactive debugging.
  3. macrumors 68040


    Eclipse is also available for the Mac. I also like NetBeans, but I use Eclipse more. Both add a few project-specific files, but nothing that prevents you from using the command line to build and run.

    If you use an IDE for Java development, try to spend as much time looking at the file structure of the source code and compiled classes as you do in the IDE itself, so you'll learn about Java itself.
  4. macrumors 6502a

    If you create a new project using the java command line utility project template, you end up with a pretty clean and useful structure for small learning/teaching exercises.

    And you get a basic ant build script that you can also use from the command line.
  5. macrumors 6502a


    Xcode is great for C++ and Java (so long as you don't expect a graphical ui builder). For Java it may not have all the bells and whistles as Eclipse or Netbeans but in my opinion it does have a simpler and cleaner interface.

    b e n
  6. macrumors member

    Eclipse better for Java

    I write a lot of Java and i just think Eclipse is much easier to use. Eclipse is great and much faster to write code with for JAVA, not objective c. Don't know much about C++. Ive also heard NetBeans is great.
  7. macrumors member

    I find that neither solution is perfect. I use Xcode in the single document per window mode and really like that - its easy to pull information from multiple sources that way.

    Eclipse has that one-giant-window school of thought. It's probably less confusing if it's for school projects with a console based main() and a few supporting classes.

    The way it reports build errors also seems less confusing.

    But because in addition to the crap I'm doing for school, I'm working on iPhone stuff, I find I'm using Xcode for java just because I like the overall interface better.
  8. macrumors member

    But how do you get Xcode to build, run/debug a single file of java? it's all greyed out for me.
  9. macrumors 6502a

    You have to go to File -> New Project and pick any of the Java templates.
  10. macrumors regular

    Dale Cooper

    As mentioned, sounds like it would be much less of a hassle to download some plain text editor like Smultron or TextWrangler than messing around with xcode projects...
  11. macrumors member

    You create a new Java project in Xcode, then add that single Java file to the project. Xcode requires a project in order to know how to build and run. Just like most other IDE's.
  12. macrumors member

    Yeah, you've got to start a project. Use the Java Tool thing for the console stuff you start out with. Then to run (and use the console) you have to actually pull up the console window under the Run menu.

Share This Page