Monday, April 25, 2011

Why does ant think I have an old version of Java?

I am trying to build Groovy from source (on RH Linux) using ant, but for some reason it thinks that my Java version is 1.4, and not 1.6, and thus it won't compile. The offending lines seem to be

<condition property="groovy.build.vm5">
    <not>
        <contains string="${ant.java.version}" substring="1.4"/>
    </not>
</condition>

in build.xml.

When I type javac -version on the command line, it displays "javac 1.6.0_11". Any ideas?

From stackoverflow
  • Check the value of the environment variables JDK_HOME and JAVA_HOME.

    EDIT: "which java" will tell you which Java you're getting when you run java from the command line. If this tells you, for example, that you're getting "/usr/lib/jvm/java-6-sun/bin/java", you can set "JAVA_HOME" to "/usr/lib/jvm/java-6-sun"

    Eyvind : I don't have those. Suppose I could add them, if they really are needed.
    Aaron Digulla : Do that. This way, you can be sure which java version ant will pick up.
    Aaron Digulla : Don't forget to look into .antrc!
  • I would check PATH environment variable.

    What do you get when you on a clean shell (recently started) execute:

    $ java -version

    Ant probably thinks you are trying to user OpenJDK's JVM and compiler (I think it comes installed with RH). Try uninstalling that too.

    Eyvind : java -version prints java version "1.6.0_11" Java(TM) SE Runtime Environment (build 1.6.0_11-b03) Java HotSpot(TM) 64-Bit Server VM (build 11.0-b16, mixed mode) I cannot uninstall anything, as this is a computer provided by the faculty
    Leonel : Wrong. Ant does not care about $PATH, instead it uses $JAVA_HOME to find the compiler and VM executables. If $JAVA_HOME is empty, it will guess the executables from the VM that is running Ant.
  • The answer of Jon Bright hints in a good direction: Possibly your installation of ant uses another java-version than the one you access via 'java -version'. This is influenced by the environment-variables JDK_HOME and JAVA_HOME.

    EDIT: If these variables are not present, then ant should find the Java from the installation that called ant. But if you set these variables, ant will pick these. So setting this variables to the installation of JDK1.6 should be worth a try. On Linux your Java could be on a subdirectory of /usr/lib/jvm.

    Eyvind : As i wrote in a comment to Jon as well: those variables are not present in my system. I guess I could set them, though. What would be the correct values? Just "/local/bin/java"?
    Mnementh : If these variables are not present, then ant should find the Java from the installation that called ant. But if you set these variables, ant will pick these. So setting this variables to the installation of JDK1.6 should be woth a try. On Linux your Java could be on a subdirectory of /usr/lib/jvm.

0 comments:

Post a Comment