11
votes

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

4
Perhaps you are running some unit or integration tests as part of the build, eg with the maven surefire or failsafe plugins? ... and are these also using Java 7? (Coz it looks like Jenkins is forking a process to run something using a Java6 JVM).sbk
Yes, you are right, I'm running junit suite with the surefire plugin and the code there is JDK 7 dependant because multi-catch statement is not supported in -source 1.6Atanas Kanchev

4 Answers

12
votes

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>
4
votes

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

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

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

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

Change above location according to your use and installation location.

0
votes

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.

-1
votes

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