javamaven-2

Why maven ignores my JAVA_HOME?


This is what I'm getting when mvn is executed from CruiseControl:

Unable to locate the Javac Compiler in:
  /usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/../lib/tools.jar
Please ensure you are using JDK 1.4 or above and
not a JRE (the com.sun.tools.javac.Main class is required).
In most cases you can change the location of your Java
installation by setting the JAVA_HOME environment variable.

At the same time, starting it from command line gives correct result. Why mvn is going into this tools.jar? Why it is ignoring my JAVA_HOME? And how can I fix it?

I don't know what are the values of JAVA_HOME/PATH when mvn is started from CC. I would really love to get this information but I don't know how. CC itself is started from user cc and env for this user gives me (it's CentOS 5.4):

JAVA_HOME=/usr/java/default
PATH=/usr/local/maven/bin:/usr/local/bin:/bin:/usr/bin:/home/cc/bin

Solution

  • Assuming that you have a linux machine.

    1. Take a look on /usr/bin/java, this is a symbolic link. Look where is a target of this symbolic link (in my case the target is at this location /etc/alternatives/java)
    2. /etc/alternatives/java is symbolic link too. Create new symbolic link to "proper" JVM (e.g. Sun's JVM)
    3. Replace /etc/alternatives/java with newly created symbolic link.

    This works for Ubuntu distribution. There is an automatic way how to do that but I forgot it actually :D