maven eclipse - 不支持 major.minor 版本 52.0
maven eclipse - Unsupported major.minor version 52.0
我正在使用 apache maven 3.2.3 编译我的 java 项目。
当我使用命令行启动编译时
mvn clean compile
那就完美了。
但是当我 运行 从 eclipse (LUNA) 构建 maven 时,它总是失败并出现以下错误:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.5.1:compile (default-compile) on project MSDPEx: Execution default-compile of goal org.apache.maven.plugins:maven-compiler-plugin:2.5.1:compile failed: An API incompatibility was encountered while executing org.apache.maven.plugins:maven-compiler-plugin:2.5.1:compile: java.lang.UnsupportedClassVersionError: com/sun/tools/javac/Main : Unsupported major.minor version 52.0
[ERROR] -----------------------------------------------------
[ERROR] realm = plugin>org.apache.maven.plugins:maven-compiler-plugin:2.5.1
[ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
[ERROR] urls[0] = file:/home/rvnath/.m2/repository/org/apache/maven/plugins/maven-compiler-plugin/2.5.1/maven-compiler-plugin-2.5.1.jar
[ERROR] urls[1] = file:/home/rvnath/.m2/repository/org/codehaus/plexus/plexus-utils/3.0/plexus-utils-3.0.jar
[ERROR] urls[2] = file:/home/rvnath/.m2/repository/org/codehaus/plexus/plexus-compiler-api/1.9.1/plexus-compiler-api-1.9.1.jar
[ERROR] urls[3] = file:/home/rvnath/.m2/repository/org/codehaus/plexus/plexus-compiler-manager/1.9.1/plexus-compiler-manager-1.9.1.jar
[ERROR] urls[4] = file:/home/rvnath/.m2/repository/org/codehaus/plexus/plexus-compiler-javac/1.9.1/plexus-compiler-javac-1.9.1.jar
[ERROR] urls[5] = file:/home/rvnath/.m2/repository/junit/junit/3.8.1/junit-3.8.1.jar
[ERROR] Number of foreign imports: 1
[ERROR] import: Entry[import from realm ClassRealm[maven.api, parent: null]]
[ERROR]
[ERROR] -----------------------------------------------------
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
是不是用eclipse和maven配置有问题?如果是这样,我该如何解决?
如果有帮助,我的环境如下:
OS: Ubuntu 14.10
JDK: java version "1.7.0_75"
OpenJDK Runtime Environment (IcedTea 2.5.4) (7u75-2.5.4-1~utopic1)
OpenJDK 64-Bit Server VM (build 24.75-b04, mixed mode)
Eclipse installed JRE's: java-7-openjdk-amd64 (default)
在过去的 2...3 周里,这个问题一直困扰着我。
这种问题问了好几遍,也回答了很多。但也发布我的答案,所以有这种情况的人可能会受益。
终于发现我的系统也安装了jdk1.8,maven的命令行启动使用的是这个版本,而eclipse使用的是1.7。所以,我做了以下事情:
- 打开 Eclipse->Window->首选项->已安装的 JRE
- 点击添加按钮,select我的jdk1.8的路径,完成
现在我可以编译项目了,尽管我不知道确切的原因,为什么它应该无法用jdk1.7编译。
首先。如果您正在使用 Maven,那么事实就在 pom 文件中,而不是在 Eclipse 中。所以你必须在 Maven 中而不是在 Eclipse 中修复问题。
首先,您必须将 maven-compiler-plugin 更新到版本 3.2 或 3.3。并像这样配置它:
<project>
[...]
<build>
[...]
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
[...]
</build>
[...]
</project>
您应该从命令行而不是从 eclipse 中检查您的构建。此外,您应该了解使用 source
、target
选项和 JDK.
之间的区别
以上对我不起作用,但这对我有用。
添加到您的 pom.xml
<project ....>
<properties>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
</project>
其中 1.7 是您打算使用的 Java 版本。这会覆盖 Maven 编译器设置,因此最好从这里进行调试。
我正在使用 apache maven 3.2.3 编译我的 java 项目。
当我使用命令行启动编译时
mvn clean compile
那就完美了。
但是当我 运行 从 eclipse (LUNA) 构建 maven 时,它总是失败并出现以下错误:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.5.1:compile (default-compile) on project MSDPEx: Execution default-compile of goal org.apache.maven.plugins:maven-compiler-plugin:2.5.1:compile failed: An API incompatibility was encountered while executing org.apache.maven.plugins:maven-compiler-plugin:2.5.1:compile: java.lang.UnsupportedClassVersionError: com/sun/tools/javac/Main : Unsupported major.minor version 52.0
[ERROR] -----------------------------------------------------
[ERROR] realm = plugin>org.apache.maven.plugins:maven-compiler-plugin:2.5.1
[ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
[ERROR] urls[0] = file:/home/rvnath/.m2/repository/org/apache/maven/plugins/maven-compiler-plugin/2.5.1/maven-compiler-plugin-2.5.1.jar
[ERROR] urls[1] = file:/home/rvnath/.m2/repository/org/codehaus/plexus/plexus-utils/3.0/plexus-utils-3.0.jar
[ERROR] urls[2] = file:/home/rvnath/.m2/repository/org/codehaus/plexus/plexus-compiler-api/1.9.1/plexus-compiler-api-1.9.1.jar
[ERROR] urls[3] = file:/home/rvnath/.m2/repository/org/codehaus/plexus/plexus-compiler-manager/1.9.1/plexus-compiler-manager-1.9.1.jar
[ERROR] urls[4] = file:/home/rvnath/.m2/repository/org/codehaus/plexus/plexus-compiler-javac/1.9.1/plexus-compiler-javac-1.9.1.jar
[ERROR] urls[5] = file:/home/rvnath/.m2/repository/junit/junit/3.8.1/junit-3.8.1.jar
[ERROR] Number of foreign imports: 1
[ERROR] import: Entry[import from realm ClassRealm[maven.api, parent: null]]
[ERROR]
[ERROR] -----------------------------------------------------
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
是不是用eclipse和maven配置有问题?如果是这样,我该如何解决?
如果有帮助,我的环境如下:
OS: Ubuntu 14.10
JDK: java version "1.7.0_75"
OpenJDK Runtime Environment (IcedTea 2.5.4) (7u75-2.5.4-1~utopic1)
OpenJDK 64-Bit Server VM (build 24.75-b04, mixed mode)
Eclipse installed JRE's: java-7-openjdk-amd64 (default)
在过去的 2...3 周里,这个问题一直困扰着我。
这种问题问了好几遍,也回答了很多。但也发布我的答案,所以有这种情况的人可能会受益。
终于发现我的系统也安装了jdk1.8,maven的命令行启动使用的是这个版本,而eclipse使用的是1.7。所以,我做了以下事情:
- 打开 Eclipse->Window->首选项->已安装的 JRE
- 点击添加按钮,select我的jdk1.8的路径,完成
现在我可以编译项目了,尽管我不知道确切的原因,为什么它应该无法用jdk1.7编译。
首先。如果您正在使用 Maven,那么事实就在 pom 文件中,而不是在 Eclipse 中。所以你必须在 Maven 中而不是在 Eclipse 中修复问题。
首先,您必须将 maven-compiler-plugin 更新到版本 3.2 或 3.3。并像这样配置它:
<project>
[...]
<build>
[...]
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
[...]
</build>
[...]
</project>
您应该从命令行而不是从 eclipse 中检查您的构建。此外,您应该了解使用 source
、target
选项和 JDK.
以上对我不起作用,但这对我有用。 添加到您的 pom.xml
<project ....>
<properties>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
</project>
其中 1.7 是您打算使用的 Java 版本。这会覆盖 Maven 编译器设置,因此最好从这里进行调试。