2011-11-23 105 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,這很可能會解決您的問題。