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

Mop*_*ath 6 eclipse maven unsupported-class-version

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

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

mvn clean compile
Run Code Online (Sandbox Code Playgroud)

然后它完美地运作.

但是当我从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.
Run Code Online (Sandbox Code Playgroud)

使用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)
Run Code Online (Sandbox Code Playgroud)

Mop*_*ath 10

在过去的2到3周内,这个问题令我烦恼.

已经多次询问过这类问题,并提出了许多答案.但也发布了我的答案,所以有这种情况的人可能会受益.

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

  1. 打开Eclipse-> Window-> preferences->已安装的JRE
  2. 单击Add按钮,选择我的jdk1.8的路径,完成

现在我能够编译项目,即使我不知道确切的原因,为什么它不能用jdk1.7编译.


khm*_*ise 3

第一的。如果您使用 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>
Run Code Online (Sandbox Code Playgroud)

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