maven eclipse - 不支持的 Major.minor 版本 52.0

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29314402/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 05:31:30  来源:igfitidea点击:

maven eclipse - Unsupported major.minor version 52.0

eclipsemavenunsupported-class-version

提问by Mopparthy Ravindranath

I am using apache maven 3.2.3 to compile my java project.

我正在使用 apache maven 3.2.3 来编译我的 java 项目。

When I use the command line to launch the compile using

当我使用命令行启动编译时

mvn clean compile

then it works perfectly.

然后它完美地工作。

But when I run maven build from eclipse (LUNA), it always fails with the below error:

但是当我从 Eclipse (LUNA) 运行 maven build 时,它总是失败并出现以下错误:

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

Is there a problem in configuration with eclipse and maven? If so, how do I solve this?

eclipse和maven的配置有问题吗?如果是这样,我该如何解决这个问题?

If it helps, my environment is the below:

如果有帮助,我的环境如下:

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)

采纳答案by khmarbaise

First. If you are working with Maven the truth is in the pom file and not in Eclipse. So you have to fix the problem in Maven and not in Eclipse.

第一的。如果您正在使用 Maven,那么真相就在 pom 文件中,而不是在 Eclipse 中。所以你必须在 Maven 中而不是在 Eclipse 中解决这个问题。

First you have to update the maven-compiler-plugin to version 3.2 or 3.3. and configure it like this:

首先,您必须将 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>

You should check your build from command line and not from within eclipse. Furthermore you should be aware of the difference between using source, targetoption and JDK.

您应该从命令行而不是从 eclipse 中检查您的构建。此外,您应该了解 using sourcetargetoption 和 JDK之间的区别。

回答by Mopparthy Ravindranath

This problem was vexing me for the last 2...3 weeks.

这个问题在过去的 2...3 周里一直困扰着我。

This kind of question has been asked several times, and many answers. But posting my answer as well, so someone having this situation may benefit.

这种问题已经问过好几次了,答案也很多。但是也要发布我的答案,因此遇到这种情况的人可能会受益。

Finally I figured out that my system also had a jdk1.8 installed, and that the cmdline launch of maven was using this version, while the eclipse was using 1.7. So, I did the following:

最后发现我的系统也安装了jdk1.8,maven的cmdline启动用的是这个版本,而eclipse用的是1.7。所以,我做了以下事情:

  1. open Eclipse->Window->preferences->Installed JRE's
  2. click Add button, select the path to my jdk1.8, finish
  1. 打开 Eclipse->Window->preferences->Installed JRE's
  2. 点击添加按钮,选择我的jdk1.8的路径,完成

Now I am able to compile the project, even though I do not know the precise reason, why it should fail to compile with jdk1.7.

现在我可以编译该项目了,尽管我不知道确切的原因,但为什么它会用 jdk1.7 编译失败。

回答by George

The above didn't work for me, but this did. Add to your pom.xml

以上对我不起作用,但这对我有用。添加到您的pom.xml

<project ....>
    <properties>
        <maven.compiler.source>1.7</maven.compiler.source>
        <maven.compiler.target>1.7</maven.compiler.target>
    </properties>
</project>

where 1.7 is the Java version you intend to use. This overwrites the maven compiler setting, so it's good to debug from here.

其中 1.7 是您打算使用的 Java 版本。这会覆盖 maven 编译器设置,因此最好从这里进行调试。