I have an Android Project called Hello on my Ubuntu 10.04 i386 Server (headless). It contains all things an Android project folder should have. I first build the project in bash while in the Project folder using this synax:
./android create project --target 5 --name HelloCompile --path ../../Projects/Hello --activity HelloActivity --package com.code.Hello
then I try to build the .apk with ant like so:
ant debug
I get this error:
BUILD FAILED
/home/myusername/www/sdk/tools/ant/main_rules.xml:384: Unable to find a javac compiler;
com.sun.tools.javac.Main is not on the classpath.
Perhaps JAVA_HOME does not point to the JDK.
It is currently set to "/usr/lib/jvm/java-6-openjdk/jre"
which is very confusing to me because just before I run ant debug
I run:
export JAVA_HOME=/usr/lib/jvm/java-6-openjdk
which I know works because printenv
in bash shell returns:
JAVA_HOME=/usr/lib/jvm/java-6-openjdk
to compound this, adding this line to my /etc/environment file
export JAVA_HOME=/usr/lib/jvm/java-6-openjdk
does not fix the problem either - I get the same error. Nothing I do changes the fact Ubunut still thinks /usr/lib/jvm/java-6-openjdk/jre
is the JAVA_HOME. What is going wrong? I've been at this for too many hours.
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:
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:
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 trailingjre
). 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 withJAVA_HOME
beyond thatjavac
is typically found in a subdirectory underJAVA_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 sobut it might be done slightly differently depending on your setup. If you do
and you see a javac executable, then the above modification of the path variable will work without any need to change it.
Changing JAVA_HOME and PATH are insufficient.
After installing the Java JDK version that you want (Java DEVELOPMENT Kit, not just Java Runtime Environment JRE), change your preferred version with
sudo update-alternatives --config java
. If you're on Ubuntu, you probably have 1.6 and 1.7 installed, and 1.8 is available in the PPAs (though I can't find a PPA of 1.8 that's not old).