Reputation: 31749
I'm trying to compile my project with "ant build", but I'm getting this error:
Unable to locate tools.jar. Expected to find it in /usr/lib/jvm/java-6-openjdk/lib/tools.jar
I searched tools.jar
and it is just in /usr/lib/jdk1.7.0_01/lib/tools.jar
.
Is a good idea to create a symlink like this below?
ln -s /usr/lib/jdk1.7.0_01/lib/tools.jar /usr/lib/jdk1.7.0_01/lib/tools.jar
Well.. actually I tried to create that symlink, but then I'm getting this error:
BUILD FAILED /home/me/code/StockWatcher/build.xml:29: java.lang.UnsupportedClassVersionError: com/sun/tools/javac/Main : Unsupported major.minor version 51.0
So I don't know if this last error is because the symlink...
Javi
Upvotes: 4
Views: 4823
Reputation: 14940
No creating the symlink is not a good idea (mixing two JDKs)
Ant is using the same Java version used to run Ant itself. If you want to use Java 1.7 you should instruct Ant. From the javac
Task documentation:
It is possible to use different compilers. This can be specified by either setting the global build.compiler property, which will affect all tasks throughout the build, by setting the compiler attribute, specific to the current task or by using a nested element of any typedeffed or componentdeffed type that implements org.apache.tools.ant.taskdefs.compilers.CompilerAdapter. Valid values for either the build.compiler property or the compiler attribute are:
- classic (the standard compiler of JDK 1.1/1.2) – javac1.1 and javac1.2 can be used as aliases.
- modern (the standard compiler of JDK 1.3/1.4/1.5/1.6/1.7) – javac1.3 and javac1.4 and javac1.5 and javac1.6 and javac1.7 (since Ant 1.8.2) can be used as aliases. jikes (the
- Jikes compiler).
- jvc (the Command-Line Compiler from Microsoft's SDK for Java / Visual J++) – microsoft can be used as an alias.
- kjc (the kopi compiler).
- gcj (the gcj compiler from gcc).
- sj (Symantec java compiler) – symantec can be used as an alias. extJavac (run either modern or classic in a JVM of its own).
If you want to use the same Java version as Ant be sure that you installed it correctly (and that you installed the JDK and not only JRE)
Upvotes: 2
Reputation: 103847
What's the value of your JAVA_HOME
environment variable? I believe this is what Ant looks at to determine where the JVM lives.
Consequently if you set this environment variable to /usr/lib/jdk1.7.0_01
this is likely to resolve your issue.
Upvotes: 0
Reputation: 10789
You have difference in references to JVM. Create symlink form one version to another it is actualy bad idea, because you violate version compatibility. If your ant use some properties as you said /usr/lib/jvm/java-6-openjdk/lib/tools.jar
it is better to find file with that properties and change it to your real location.
Upvotes: 1