java version

how do I tell xcode which version of java ot use?

I have 1.5 installed, but xcode insists on using 1.3

iBook G4, Mac OS X (10.4.6)

Posted on Jun 24, 2006 3:04 PM

Reply
8 replies

Jun 24, 2006 3:35 PM in response to tricolaire

Hi tricolaire

This well known patch fixes this problem. You need to start the Terminal program and type in these commands exactly. Press Return after each line:

cd /System/Library/Frameworks/JavaVM.framework/Versions/
sudo unlink CurrentJDK
(enter your password here)
sudo ln -s 1.5 CurrentJDK
(The second word is small "L" small "N", short for "link")

To confirm that you're now using Java 1.5, type the following command:
java -version

Good luck

Bob

Jun 25, 2006 3:11 AM in response to tricolaire

Hi

We need more information:
- What type of project are you creating? (Java tool, etc).
- When exactly do you get the error message? What commands do you enter to cause the error? what other messages do you get?

Can you copy the error message and surrounding text and post it here?

The more information you give us, the easier it will be to help you

Bob

Jun 25, 2006 7:42 AM in response to Bob Lang1

Hi tricolaire & Bob,

First, I'm not a java developer so I'll defer to those who probably know much more about this than me. But I was recently looking for an answer to the same question for my wife (who has to support some java apps on Macs).

There's a discussion about changing the symlinks as Bob has suggested on MacOSXHints, including a little shell script that automates the process, here:

http://www.macosxhints.com/article.php?story=20060121171126988

However, the discussion following the hint also includes some argument against simply changing the symlink and instead recommends using the "Java Preferences" utility that is installed along with J2SE 5. The preference utility can be found in the "/Applications/Utilities/Java/J2SE 5.0" folder.

An Apple support document related to the J2SE 5.0 update obviously suggests using their preference utility, here:

http://docs.info.apple.com/article.html?artnum=302412

Personally I can't comment on the relative merits of using one method over the other, but you might want to check out the links and see if they offer any help.

Steve

Jun 25, 2006 8:58 AM in response to Steve Herman1

Hi Steve

I've never, ever got the preference utility to work as advertised - and a number of other people have reported problems with it. Even so, it's worth a try.

However, on further investigation of Xcode I discovered some well-hidden project settings which might have a bearing on the problem. If you go to the "Project" menu then "Edit active target 'TargetName'" you'll find a page of settings pops up. Select "Java Compiler Settings" and make sure that Target VM and Source versions are correctly set.

Bob

Jul 3, 2006 11:03 PM in response to tricolaire

Hi!

I have spent way too much time trying to get Xcode to build a simple Hello World java application using Java 1.5.

Everything everyone else has said is quite good but I have one more tip.

If you build a simple java application using the "Ant-based Application Jar" template, the actual template has a build.xml file that contains source="1.3" target="1.3" as parameters for javac.

So, what I did was copy the entire folder:

/Library/Application Support/Apple/Developer Tools/Project Templates/Java/Ant-Based Application Jar/

to:

/Library/Application Support/Apple/Developer Tools/Project Templates/Java/Ant-Based Application Jar 1.5/

Then, I edited the included build.xml (in the copy) by changing source="1.3" target="1.3" to source="1.5" target="1.5" .

Now when I create a new project, I can choose between the two templates based upon whether or not I need 1.5.

Hope this helps (and I hope it is correct).

And here is the great Xcode "Hello World!" walkthrough from Sun:
http://java.sun.com/docs/books/tutorial/getStarted/cupojava/mac.html

-- Charlie



iBook G4 Mac OS X (10.4.7)

iBook G4 Mac OS X (10.4.7)

iBook G4

Jul 17, 2006 3:47 PM in response to Bob Lang1

Thanks to everybody for this discussion! It was very helpful! Here's my precedural note for setting the correct java in Xcode in the future, based on your discussion. Until this, I first set Java Preferences to use version J2SE 5.0, and used TextWrangler (source editor) and AppleScript (for automation and less typing) and Terminal to get Java 1.5 to be used. Here's my note (replace "my second java tool" with your project's name):

To correct the compiler for “my second java tool”:
1. Open “my second java tool” project
2. Project / Edit Active Target “my second_javatool”
3. Settings / Simple View / Java Compiler Settings
4. Target VM Version: 1.5
5. Source VM version: 1.5

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

java version

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.