Trying to compile with ant

I'm trying to compile my project using ant build ", but I get this error:

Unable to find tools.jar. It was expected to find it in / usr / lib / jvm / java -6-openjdk / lib / tools.jar

I was looking for tools.jar and it is just located in /usr/lib/jdk1.7.0_01/lib/tools.jar .

Is it possible to create a symbolic link as shown below?

ln -s / usr / lib / jdk1.7.0_01 / lib / tools.jar / usr / lib / jdk 1.7.0_01 / lib / tools.jar

Well .. actually I tried to create this symbolic link, but then I get this error:

BUILD FAILED / home / me / code / StockWatcher / build.xml: 29: java.lang.UnsupportedClassVersionError: com / sun / tools / javac / Main: Unsupported version major.minor 51.0

So, I do not know if this last error was because the symbolic link ...

Xavi

+4
source share
3 answers

Creating a symlink is not a good idea (mixing two JDKs)

Ant uses the same version of Java as running Ant. If you want to use Java 1.7, you must instruct Ant. From javac Documentation:

You can use different compilers. This can be determined either by setting the global property build.compiler, which will affect all tasks in the entire assembly, by setting the compiler an attribute specific to the current task, or by using a nested element of any typed or component type that implements org.apache.tools.ant.taskdefs .compilers.CompilerAdapter. Valid values ​​for the build.compiler property or compiler attribute are:

  • classic (standard JDK 1.1 / 1.2 compiler) - javac1.1 and javac1.2 can be used as aliases.
  • the modern one (standard JDK 1.3 / 1.4 / 1.5 / 1.6 / 1.7 compiler) - 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 (
  • Jikes compiler).
  • jvc (command line compiler from the Microsoft SDK for Java / Visual J ++) - microsoft can be used as an alias.
  • kjc (kopi compiler).
  • gcj (gcj compiler from gcc).
  • sj (Symantec java compiler) - symantec can be used as an alias. extJavac (runs either modern or classic in the native JVM).

If you want to use the same version of Java as Ant, make sure you install it correctly (and you installed the JDK, not just the JRE)

+2
source

You have a difference in the links to the JVM. Create a symbolic form from one version to another, this is a really bad idea because you are breaking version compatibility. If your ant uses some properties, as you said /usr/lib/jvm/java-6-openjdk/lib/tools.jar , it is better to find a file with these properties and change it to its real location.

+1
source

What is the value of your JAVA_HOME environment variable? I believe that this is what Ant is trying to determine where the JVM lives.

Therefore, if you set this environment variable to /usr/lib/jdk1.7.0_01 , this may solve your problem.

0
source

Source: https://habr.com/ru/post/1382740/


All Articles