Maven/Jenkins java.lang.UnsupportedClassVersionError: Unsupported major.minor version 51.0

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14938114/
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-10-31 17:56:22  来源:igfitidea点击:

Maven/Jenkins java.lang.UnsupportedClassVersionError: Unsupported major.minor version 51.0

mavenjenkinsjava

提问by Atanas Kanchev

I have a Jenkins server having JDK & JRE 6 and 7 installed together.

我有一个安装了 JDK 和 JRE 6 和 7 的 Jenkins 服务器。

All of the projects are built on 1.6 except one which is 1.7 dependent.

除了依赖于 1.7 的项目之外,所有项目都建立在 1.6 上。

I've configured the maven pom file to use the Java compiler from the JAVA_HOME_7 environment PATH.

我已将 maven pom 文件配置为使用 JAVA_HOME_7 环境路径中的 Java 编译器。

<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.0</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                    <showDeprecation>true</showDeprecation>
                    <showWarnings>true</showWarnings>
                    **<executable>${env.JAVA_HOME_7}/bin/javac</executable>**
                    <fork>true</fork>
                    <verbose>false</verbose>
                </configuration>
            </plugin>

During mvn install I'm getting the following error:

在 mvn install 期间,我收到以下错误:

java.lang.RuntimeException: There was an error in the forked process
java.lang.UnsupportedClassVersionError: : Unsupported major.minor version 51.0

which I think means that the server is using JRE 1.6.

我认为这意味着服务器正在使用 JRE 1.6。

How to keep the JRE 1.6 together with 1.7 in order to keep the compatibility with the old 1.6 projects and the new 1.7 one?

如何将 JRE 1.6 与 1.7 保持在一起以保持与旧的 1.6 项目和新的 1.7 项目的兼容性?

Many Thanks, Atanas

非常感谢,阿塔纳斯

回答by sbk

You will need to run surefire tests with java 7 too. By default surefire will use same jvm as that running maven - Java6 in your case.

您还需要使用 java 7 运行 surefire 测试。默认情况下,surefire 将使用与运行 maven 相同的 jvm - 在您的情况下为 Java6。

  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-surefire-plugin</artifactId>
      <version>2.13</version>
      <configuration>
        ...
        <jvm>${env.JAVA_HOME_7}/bin/java</jvm>
      </configuration>
    </plugin>
  </plugins>

回答by Rais Alam

I remember I also struggled to this problem. Follow below steps to resolve the problem

我记得我也在努力解决这个问题。请按照以下步骤解决问题

Cause:when multiple JRE is installed then multiple java.exeis also installed to many location of system.

原因:当安装了多个 JRE 时,多个java.exe也会安装到系统的许多位置。

Solution:Modify your environment PATHvariable and change the order of java.exe. put location of java.exeon first position like below code

解决方案:修改你的环境PATH变量并更改java.exe的顺序。将java.exe 的位置放在第一个位置,如下面的代码

PATH = C:\Program Files\Java\jdk1.6.0\; other;other;other

PATH = C:\Program Files\Java\jdk1.6.0\; 其他;其他;其他

Change above location according to your use and installation location.

根据您的使用和安装位置更改上述位置。

回答by wtsolid

I have encountered this problem more than once, it is because you have more than one versions of jdk(jre) on your system, so just set the JAVA_HOME to the proper jdk you compile your project with and the running would be fine.

这个问题我遇到过不止一次,是因为你的系统上有多个版本的jdk(jre),所以只要将JAVA_HOME设置为你编译项目时使用的正确jdk,运行就可以了。

回答by CoMpLeXiTy

Have a look at your target/lib directory, you might have two versions of same jar. For me it was creating the pro

看看你的 target/lib 目录,你可能有两个版本的同一个 jar。对我来说,它正在创造专业