Java 5 Setup on OS X [update]


I promised to write an article ’bout getting Java 5 to work on Mac OS X. I needed this in preparation for my programming courses at university. So, first of all I found out that Java 5 is actually not 5.0 but 1.5, confusing, he?

So to begin with, you need OS X Tiger, it is reported to work work on Panther, too, but that requires a little configuration of the installer package with Pacifist. Let’s move, time is money… hehe. First of all you need to download Java 5 Beta from the Apple website. Follow the installer:

Installer

Now you go to /Applications/Utilities/Java/J2SE 5.0 in Finder and start Java Preferences. From within there you make some necessary changes. Change “Use version:” to J2SE 5.0 and at runtime settings drag J2SE 5.0 to be above J2SE 1.4.2. That’s it. Click Save at the bottom of the window and quit.

Java 5 Preferences

You’re ready to use Java 1.5 on your Mac, but wait, where is the compiler? Well, I can tell you, it resides in /System/Library/Frameworks/JavaVM.framework/Versions/1.5/Commands/javac. Nice, is’nt it? If you want to work with XCode you can change the compiler – as well as the executable path for every project to match Java 5 Binarys.

I found this annoying and decided to take a XCode template and set it up to use Java 1.5. It’s pretty simple! Just get an existing Java Template from /Library/Application Support/Apple/Developer Tools/Project Templates/Java. I took the Java Tool folder and copied it over to my Desktop. Now i opened it in XCode and let XCode update it.

Following this article from Apple you change the following:

Update: There is a problem with the new template, indeed it seems that XCode 2.1 does not update the -jar argument (projectnameasidentifier).jar. Yaw Anokwa commented on this and was able to create an XCode template which fixes this issue. You can download it from here. Follow the instructions.txt in the archive.

Thanks to Yaw Anokwa for pointing this out.

Target Settings:
Double click the target to edit and provide /System/Library/Frameworks/JavaVM.framework/Versions/1.5/Commands/javac as the value for the JAVA_COMPILER build setting. Change the Target VM Version and Source Version in the Java Compiler Setting to use 1.5.
(To do this select ‘Default’ to show configuration at the top left of the window. Then select Expert View, then Java Compiler Settings.)

XCode Target Settings

Executable Settings:
Double click the executable named java and enter /System/Library/Frameworks/JavaVM.framework/Versions/1.5/Commands/java as the Executable Path in the General tab of Executable info.
XCode Executeable Settings

Now you are almost finished. To have a better sorting in the Templates window of XCode i created a new folder in the Project Templates Directory named ‘Java 5′. Now i again copy the new template from my Desktop over to the Java 5 folder.

Java 5 Tool

Now you create a new project in XCode you will find our Java 5 Tool template. You can do that with all the other Java templates if you want.

XCode Project Templates

  1. #1 by Yaw Anokwa on October 30, 2005 - 06:53

    This was a really useful reference, but I ran into a problem where I could compile but could not run the Java 5 code.

    It seems that Xcode 2.1 project file mangles the -jar «PROJECTNAMEASIDENTIFIER».jar argument in the executable. Fortunately, I was able to tweak the old Xcode file to make it work and I have posted copy of the working template and installation instructions here:

    http://www.anokwa.com/XCodeTemplate_Java5.zip

  2. #2 by Ahbe on November 26, 2005 - 02:13

    AAAhhhh…. FINALLY! IT WORKS! Ok, I’ll admit I’m new to this, and I have been struggling for some time now to get Java 5 to work in Xcode. Thank you Yaw Anokwa for your helpful template. It’s works wonderfully in Xcode 2.2.

  3. #3 by Henrik on December 8, 2005 - 22:03

    i installed Java 1.5, and opened Xcode. I have made the proper changes described in this Article, but when i try to compile my Project, it says “Command /Developer/Private/jam failed with exit code 127″ in the “build results” window.

    Can anyone help?

  4. #4 by Finch on December 14, 2005 - 18:20

    Excellent guide! Thanks for taking the time to write it! :)

  5. #5 by Roger Dannenberg on January 15, 2006 - 20:42

    I found the Apple article helpful up to the point where it says double click on the java executable … what java executable? I couldn’t find one, and my application compiled with Java 1.5 but failed with no error when run from the Finder. I was able to cd inside the application with a shell and see error messages. I was also able to start my java code by giving an explicit path to the 1.5 version of Java. I found this hint at Apple — http://developer.apple.com/releasenotes/Java/Java50Release3RN/index.html — that suggested setting the JVMVersion key of the Info.plist in the Application. I was able to make my application work from the Finder after manually editing the plist. Finally, I found on my Target window in Xcode, visited by double clicking the target, under Info.plist entries, Simple View, Pure Java Specific, a dropdown box called “Target VM Version”. I typed in “1.5+” (without the quotes) and then the application worked. Note that I also had to change the target settings, source settings, and JAVA_COMPILER build setting as instructed above.

  6. #6 by SJ on March 6, 2006 - 20:45

    For your error
    “Command /Developer/Private/jam failed with exit code 127″

    Xcode cannot find the path to the Developer directory. Set the right path.

Comments are closed.