升级到Java7,Missing Tools.jar和错误的类版本后构建失败 [英] Builds failing after upgrading to Java7, Missing Tools.jar and bad class versions
问题描述
我最近在Macbook Pro上升级到Java7。我下载了JDK(不是JRE)。
I recently upgraded to Java7 on my Macbook Pro. I downloaded the JDK (not the JRE).
» javac version
javac 1.7.0_17
» echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home
然而,当尝试运行构建时,其中一个maven编译器插件失败,声称我安装了JRE:
However, when trying to run a build, one of the maven compiler plugins is failing, claiming I have a JRE installed:
» mvn install
[ERROR] execute error
org.apache.maven.plugin.MojoExecutionException: You need to run build with JDK
or have tools.jar on the classpath.
If this occures during eclipse build make sure you run eclipse under JDK as well
at com.mysema.maven.apt.AbstractProcessorMojo.execute(AbstractProcessorMojo.java:263)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
我很困惑,因为我显然安装了JDK。我的 MAVEN_OPTS
不做任何有趣的事情:
I'm confused, as I clearly have a JDK installed. My MAVEN_OPTS
don't do anything funny:
» echo $MAVEN_OPTS
-Xmx512m
尝试调试,我检查了有关插件的来源,其执行以下操作:
Trying to debug, I checked the source of the plugin in question, which is doing the following:
try {
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
if (compiler == null) {
throw new MojoExecutionException("You need to run build with JDK or have tools.jar on the classpath."
+ "If this occures during eclipse build make sure you run eclipse under JDK as well");
}
这似乎无害,所以我怀疑我的命令行env出错了,写了一个简单的测试:
That seems harmless, so I suspected something wrong on my command line env, and wrote a simple test:
// Main.java
import javax.tools.JavaCompiler;
import javax.tools.ToolProvider;
public class Main {
public static void main(String[] args) {
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
if (compiler == null)
{
System.out.print("Compiler is null");
} else {
System.out.print("Compiler is not null");
}
}
}
» javac Main.java
Main.java:1: cannot access javax.tools.JavaCompiler
bad class file: /Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home/jre/lib/rt.jar(javax/tools/JavaCompiler.class)
class file has wrong version 51.0, should be 49.0
Please remove or make sure it appears in the correct subdirectory of the classpath.
import javax.tools.JavaCompiler;
^
1 error
如果我理解错误,建议Java7编译器针对Java5运行 rt.jar
?
If I understand that error correctly, it suggests a Java7 compiler running against a Java5 rt.jar
?
我不确定这里发生了什么。
I'm not sure what's going on here.
我显然安装了Java7 JDK,但不明白:
I clearly have a Java7 JDK installed, but don't understand:
- 为什么maven插件为编译器返回null?
- 为什么我会出现类版本错误?
答案表明JRE / JDK安装混乱。我同意这似乎很可能,但无法追查罪魁祸首所在的位置。
Answers are suggesting a messed up JRE / JDK install. I agree this seems likely, but having trouble tracking down where the culprit lies.
一些额外的信息:
» which javac
/usr/bin/javac
ls -ltra /usr/bin/javac
/usr/bin/javac -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/javac
cd /System/Library/Frameworks/JavaVM.framework/Versions
ls -ltra
lrwxr-xr-x 1 root wheel 10 18 Feb 08:36 1.6.0 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 18 Feb 08:36 1.6 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 18 Feb 08:36 1.5.0 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 18 Feb 08:36 1.5 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 18 Feb 08:36 1.4.2 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 18 Feb 08:36 1.4 -> CurrentJDK
drwxr-xr-x 8 root wheel 272 18 Feb 08:39 A
drwxr-xr-x 11 root wheel 374 18 Feb 08:39 ..
lrwxr-xr-x 1 root wheel 1 14 Jun 11:14 Current -> A
lrwxr-xr-x 1 root wheel 58 14 Jun 11:15 CurrentJDK -> /Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents
drwxr-xr-x 11 root wheel 374 14 Jun 11:15 .
因此,正在运行的javac是安装在 A /命令中的javac
。我不确定这是否正确。我的Windows时代似乎有些不对劲,但我对Mac对待Java安装的方式不太熟悉。
So, the javac that is running is the one installed in A/Commands
. I'm not sure if this is correct or not. It seems wrong from my windows days, but I'm not familiar enough with how Mac treats Java install to go tinkering.
我的 $ JAVA_HOME
指向 /Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home
,其中包含以下内容:
My $JAVA_HOME
points to /Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home
, which has the following:
drwxrwxr-x 10 root wheel 340 5 Feb 08:10 jre
-rw-rw-r-- 1 root wheel 123324 5 Feb 08:10 THIRDPARTYLICENSEREADME-JAVAFX.txt
drwxrwxr-x 5 root wheel 170 5 Feb 08:10 man
drwxrwxr-x 9 root wheel 306 2 Mar 02:10 db
-rw-rw-r-- 1 root wheel 3339 2 Mar 02:10 COPYRIGHT
drwxrwxr-x 9 root wheel 306 2 Mar 02:10 include
-rw-rw-r-- 1 root wheel 19997030 2 Mar 02:10 src.zip
-rw-rw-r-- 1 root wheel 447 2 Mar 02:10 release
-rw-rw-r-- 1 root wheel 172252 2 Mar 02:10 THIRDPARTYLICENSEREADME.txt
-rw-rw-r-- 1 root wheel 114 2 Mar 02:10 README.html
-rw-rw-r-- 1 root wheel 40 2 Mar 02:10 LICENSE
drwxrwxr-x 5 root wheel 170 2 Mar 02:10 ..
drwxrwxr-x 15 root wheel 510 2 Mar 02:13 .
drwxrwxr-x 13 root wheel 442 2 Mar 02:13 lib
drwxrwxr-x 43 root wheel 1462 2 Mar 02:13 bin
推荐答案
我发现 tools.jar
坐在 / Library / Java / Extensions
我不确定这是不是标准。
I'm not sure if this is standard or not.
但是,将 tools.jar
从JDK7 $ JAVA_HOME / lib
复制到 / Library / Java / Extensions
解决了我所有的问题。
However, copying the tools.jar
from the JDK7 $JAVA_HOME/lib
to /Library/Java/Extensions
solved all my problems.
我还应该指出,在我最初的问题中,我更新了Java CurrentSDK
指向 JDK7
:
I should also point out that in my original question I had updated the Java CurrentSDK
to point to JDK7
:
CurrentJDK -> /Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents
这是一个坏主意,正如此处所指出的那样。
This was a Bad Idea, as pointed out here.
我更新了这一点以指回到1.6。虽然这看起来有点违反直觉,但它需要让事情有效。
I updated this to point back to 1.6. Although this seems counter-intuitive, it was required to get things working.
/System/Library/Frameworks/JavaVM.framework的当前列表/ Versions
带 1.7
JDK如下所示:
The current listing of /System/Library/Frameworks/JavaVM.framework/Versions
with a 1.7
JDK looks as follows:
lrwxr-xr-x 1 root wheel 10 18 Feb 08:36 1.6.0 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 18 Feb 08:36 1.6 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 18 Feb 08:36 1.5.0 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 18 Feb 08:36 1.5 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 18 Feb 08:36 1.4.2 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 18 Feb 08:36 1.4 -> CurrentJDK
drwxr-xr-x 8 root wheel 272 18 Feb 08:39 A
drwxr-xr-x 11 root wheel 374 18 Feb 08:39 ..
lrwxr-xr-x 1 root wheel 1 14 Jun 11:35 Current -> A
lrwxr-xr-x 1 root wheel 59 14 Jun 12:31 CurrentJDK -> /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents
drwxr-xr-x 11 root wheel 374 14 Jun 12:31 .
这篇关于升级到Java7,Missing Tools.jar和错误的类版本后构建失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!