Java – Ant blatantly ignores JAVA_HOME environment variables

Ant blatantly ignores JAVA_HOME environment variables… here is a solution to the problem.

Ant blatantly ignores JAVA_HOME environment variables

I just got the latest version of the Android SDK and started trying it out. Unlike almost everyone else who has encountered this issue, I am running Linux, which is Linux Mint 13. I’m currently trying to compile a Hello World program with ant, via installation

sudo apt-get install ant

And run in the project folder:

ant debug

However, it fails to compile at all and ends up spitting out an error related to setting JAVA_HOME. I modified my ~/.bashrc file accordingly and restarted, but I still get the error :

Perhaps JAVA_HOME does not point to the JDK.
It is currently set to "/usr/lib/jvm/java-7-openjdk-amd64/jre"

Total time: 1 second
jamie@jamie-ThinkPad-E525 ~/Downloads/adt-bundle-linux/sdk/tools/projects/new $ echo $JAVA_HOME
/usr/java/jdk1.7.0_05/

As you can see, it’s lying in Dentry.

I’ve found a lot of references on this issue, but most people either set their JAVA_HOME incorrectly or set it to JRE. Obviously, I haven’t done neither.

I also modified the ant.properties file of the project folder to add this line

java.home=/usr/java/jdk1.7.0_05/

Useless.

Has anyone else encountered/solved this issue, or had any ideas? Thank you.

Solution

Chances are Ant is telling the truth and the environment variable is not set. Chances are:

  • You entered the wrong statement in the “.bashrc” file, or
  • You did not restart correctly.

Anyway, you can verify this by running export in the shell before running the ant command… and see JAVA_HOME variables are listed.


Hint:

1) This is wrong:

JAVA_HOME=/usr/java/jdk1.7.0_05/

This only creates a local shell variable, and the local shell variable is not passed to child processes (such as the ant command). It should be:

export JAVA_HOME=/usr/java/jdk1.7.0_05/

2) Try running this:

export JAVA_HOME=/usr/java/jdk1.7.0_05/
ant

3) Adding java.home=/usr/java/jdk1.7.0_05/ to ant.properties will not help. Ant requires settings in environment variables.

4) Computer programs don’t lie. They speak the truth they see. Or more accurately, the whole concept of lying and telling the truth is meaningless unless the agent has intent. But the point is, if you start suspecting that a computer program is trying to trick you, you’re going to have a hard time debugging things.

(Well, you’re kidding.) But many people facing troubleshooting problems take a similar, unproductive approach; For example, suppose every tricky Java problem is evidence of compiler/language/runtime corruption. IMO – it is worth reminding people that this idea can be very unhelpful ….)

Related Problems and Solutions