Ant unable to find javac, JAVA_HOME won't set on Ubuntu Ant unable to find javac, JAVA_HOME won't set on Ubuntu android android

Ant unable to find javac, JAVA_HOME won't set on Ubuntu


Did you install the JDK?

When you install Ubuntu only the JRE is installed as part of the default packages. Unfortunately Ubuntu's package management names the directory as if the JRE were installed along with the JDK. The directory is named java-6-openjdk even though the JDK is not be present.

Do the following:

sudo apt-get install openjdk-6-jdk

It will install the JDK in that same directory.


--- Updated after noticing a small item in your output ---

You have your JAVA_HOME set to the correct location for a Java Runtime Environment, which unsuprisingly will allow you to run Java programs, but not develop them.

Shorten your JAVA_HOME to /usr/lib/jvm/java-6-openjdk (note the removal of the trailing jre). After that your Ant wrappers / compiler detection code won't get confused, as it will be pointing to the home of your Java Development Environment instead of the embedded, related Java Runtime Environment.

The embedded Java Runtime Environment is provided to make sure you can test against just the core (compiler tools not included) Java offerings.

--- Original post follows ---

Finding the command javac has little to do with JAVA_HOME beyond that javac is typically found in a subdirectory under JAVA_HOME

What you need to do is to modify your PATH environmental variable to include the directory where the Java executables are located. Typically this is done like so

PATH=${PATH}:${JAVA_HOME}/binexport PATH

but it might be done slightly differently depending on your setup. If you do

ls ${JAVA_HOME}/bin

and you see a javac executable, then the above modification of the path variable will work without any need to change it.


As Edwin Buck stated, check your $PATH for softlinks to /etc/alternatives/java in the /usr/bin/ directory. They are being read before your appended JAVA_HOME variable.

That was my problem:

ls -al /usr/bin/j* lrwxrwxrwx 1 root root    22 2012-05-07 13:26 /usr/bin/java -> /etc/alternatives/javalrwxrwxrwx 1 root root    25 2011-05-12 19:45 /usr/bin/java_vm -> /etc/alternatives/java_vmlrwxrwxrwx 1 root root    24 2011-05-01 05:22 /usr/bin/javaws -> /etc/alternatives/javawslrwxrwxrwx 1 root root    26 2011-05-12 19:45 /usr/bin/jcontrol -> /etc/alternatives/jcontrollrwxrwxrwx 1 root root    23 2011-04-26 02:24 /usr/bin/jexec -> /etc/alternatives/jexec