2011-11-23 153 views
4

我试图编译我用“Ant构建”项目进行编译,但我得到这个错误:试图用蚂蚁

Unable to locate tools.jar. Expected to find it in /usr/lib/jvm/java-6-openjdk/lib/tools.jar

我搜索tools.jar,它只是在/usr/lib/jdk1.7.0_01/lib/tools.jar

创建如下所示的符号链接是一个好主意吗?

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

嗯..其实我试图创建符号链接,但后来我得到这个错误:

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

所以我不知道这最后一个错误是因为符号链接...

Javi

+1

重复的问题HTTP:这里(对于蚂蚁)http://stackoverflow.com/questions/7073485/why-is-s-and-start-in-thread-error-a-unsupporte –

+1

也在这里(对于蚂蚁)http://stackoverflow.com/questions/7073485/why-is-蚂蚁给-ME-A-不支持的,主要的,次要的版本错误 –

回答

2

没有创建符号链接是不是(混合两种版本的JDK)

蚂蚁是使用用于运行Ant本身相同的Java版本是一个好主意。如果你想使用Java 1.7,你应该指示Ant。从javac任务文档:

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).

如果您想使用相同的Java版本的Ant确保你正确地安装了它(和您所安装的JDK,而不仅仅是JRE)

1

您在引用JVM时有所不同。从一个版本创建符号链接到另一个版本,这实际上是个坏主意,因为你违反了版本兼容性。如果您的蚂蚁使用某些属性,如您所说/usr/lib/jvm/java-6-openjdk/lib/tools.jar,最好找到具有该属性的文件并将其更改为您的真实位置。

0

你的JAVA_HOME环境变量的价值是什么?我相信这是Ant看待确定JVM存在的位置。

因此,如果将此环境变量设置为/usr/lib/jdk1.7.0_01,这很可能会解决您的问题。