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

javaJenkinsmaven

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

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

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

<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:

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.

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?

Many Thanks,
Atanas

Best Answer

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.

  <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>
Related Topic