Skip navigation

Can Xcode 4.5.1 compile/run java?

4494 Views 14 Replies Latest reply: Jan 12, 2013 2:34 AM by archit4 RSS
CalvinKit Calculating status...
Currently Being Moderated
Oct 17, 2012 10:02 AM

Can Xcode 4.5.1 compile/run java?

  • Mark Szymczyk Level 4 Level 4 (1,865 points)
    Currently Being Moderated
    Oct 17, 2012 11:18 AM (in response to CalvinKit)

    Yes, it can. Create an external build system project in Xcode. Tell the project to use the Java compiler as the build tool.

     

    While Xcode can compile Java code, it's not the best tool for doing so. Eclipse and Netbeans support Java better than Xcode.

  • Mark Szymczyk Level 4 Level 4 (1,865 points)
    Currently Being Moderated
    Oct 17, 2012 9:06 PM (in response to CalvinKit)

    When you create the project, there is a Build Tool text field. Enter the path to the Java compiler there.

     

    If you've already created the project, select the project from the project navigator on the left side of the project window to open the project editor. Select your target from the left side of the project editor. Click the Info button at the top of the editor. Enter the path to the Java compiler in the Build Tool text field.

     

    External Build Tool Configuration.png

  • day-day Level 1 Level 1 (0 points)
    Currently Being Moderated
    Oct 18, 2012 2:09 PM (in response to Mark Szymczyk)

    isint the Java compiler in '/usr/bin'? I tried putting that in build tool but it fails to compile.

  • Mark Szymczyk Level 4 Level 4 (1,865 points)
    Currently Being Moderated
    Oct 18, 2012 2:33 PM (in response to day-day)

    What did you enter for the build tool?

     

    /usr/bin

     

    Or

     

    /usr/bin/javac (Assuming you're using the javac compiler)

     

    You have to supply the full path to the Java compiler. Supplying /usr/bin won't work.

  • day-day Level 1 Level 1 (0 points)
    Currently Being Moderated
    Oct 18, 2012 2:35 PM (in response to Mark Szymczyk)

    I tried both and neither worked

  • Mark Szymczyk Level 4 Level 4 (1,865 points)
    Currently Being Moderated
    Oct 18, 2012 2:46 PM (in response to day-day)

    Have you looked in /usr/bin and checked that the Java compiler is there? If no compiler is there, you're going to have install it. If the compiler is there and the build tool doesn't work, I don't have an answer for you to get it to work in Xcode. Use another IDE like Eclipse or Netbeans that has better Java support. Or use TextMate 2, which has a bundle that lets you compile and run Java code from TextMate.

  • day-day Level 1 Level 1 (0 points)
    Currently Being Moderated
    Oct 18, 2012 2:55 PM (in response to Mark Szymczyk)

    It's installed but idk. I just wanted to use XCode since I dont car efor Netbeans and Eclipse doesn't want to work with C/C++ for me. But thanks for your help.

  • Mark Szymczyk Level 4 Level 4 (1,865 points)
    Currently Being Moderated
    Oct 19, 2012 10:38 AM (in response to day-day)

    One more thing to try. You may have to add the names of the Java files you're compiling to the Arguments text field, which you can see in the screenshot I posted earlier in this thread.

  • archit4 Calculating status...
    Currently Being Moderated
    Jan 8, 2013 4:48 AM (in response to Mark Szymczyk)

    I did the same thing. it gives an error saying :

    Command /usr/bin/javac failed with exit code 2.  pleasehelp.

  • Mark Szymczyk Level 4 Level 4 (1,865 points)
    Currently Being Moderated
    Jan 8, 2013 11:42 AM (in response to archit4)

    Archit,

     

    I don't use Xcode for Java. I don't have anything to add besides restate what I stated on Oct. 18.

     

    If the compiler is there and the build tool doesn't work, I don't have an answer for you to get it to work in Xcode. Use another IDE like Eclipse or Netbeans that has better Java support. Or use TextMate 2, which has a bundle that lets you compile and run Java code from TextMate.

     

    I recommend downloading TextMate 2. It's free and it's pretty easy to compile Java code with it. Choose Bundles > Java > Compile and Run.

  • archit4 Level 1 Level 1 (0 points)
    Currently Being Moderated
    Jan 11, 2013 3:12 AM (in response to Mark Szymczyk)

    okay! Thanks, mark. i'll try textmate then.

  • etresoft Level 7 Level 7 (23,905 points)
    Currently Being Moderated
    Jan 11, 2013 6:50 AM (in response to archit4)

    It is always best to start your own question instead of piggy-backing on someone else's months-old question.

     

    Java is no longer part of OS X. If you want to use Java, or any other language that does not come with Xcode, then you must install it separately. Then you can use it in Xcode. It is best to use makefile-based projects with 3rd party languages. It is possible to closely integrate them into Xcode the same way that LLVM is integratd, but it can be quite a bit of work.

  • archit4 Level 1 Level 1 (0 points)
    Currently Being Moderated
    Jan 12, 2013 2:34 AM (in response to etresoft)

    okay. but how do you do that? how to add language into xcode?

Actions

More Like This

  • Retrieving data ...

Bookmarked By (0)

Legend

  • This solved my question - 10 points
  • This helped me - 5 points
This site contains user submitted content, comments and opinions and is for informational purposes only. Apple disclaims any and all liability for the acts, omissions and conduct of any third parties in connection with or related to your use of the site. All postings and use of the content on this site are subject to the Apple Support Communities Terms of Use.