Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running Ant with JDK 1.6 on Mac OS X

Tags:

java

macos

ant

I am having a problem running Ant with JDK 1.6 on Mac OS X. Even though Java application versions is set to Java SE 6 in OS X's Java Preference, executing java -version in Terminal also shows java version "1.6.0_07", Ant still seems to use JDK 1.5 to be using JDK 1.5 as it does not see JDK 1.6 classes when compiling my code.

I understand that Ant relies on JAVA_HOME environment variable to specify which JDK to use. However, I do not quite understand how this variable can be set on Mac OS X.

Hence, my question is how to make Ant runs with JDK 1.6 on Mac OS X. If the correct way is still to set JAVA_HOME environment variable, how to set the variable on OS X.

like image 607
ejel Avatar asked Mar 29 '09 20:03

ejel


1 Answers

The JAVA_HOME environment variable is set in your home directory's .profile file. (/Users/ejel/.profile ?) Edit it and set it to what you want it to be. E.g.:

export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home

From this point onward, every time you open a new terminal window it will have JAVA_HOME set to this new value. It will not have changed with any existing open windows.

If you are truly aghast to putting this in the profile, or if it conflicts with other software, the export statement could always be run in the terminal manually or go into a script (eg: setj6ev.sh) that is run once before you start running ant tasks.

like image 124
Stu Thompson Avatar answered Oct 13 '22 13:10

Stu Thompson