Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven uses an incorrect Java version when it is executed by Jenkins

I have some projects compiled and deployed with Maven and Jenkins and they have worked fine until now that I have changed the java version from 6 to 7.

In order to do this I executed the command sudo update-alternatives --config javac and changed the values of JAVA_HOME and PATH in the /etc/profile file. I have also modified the pom file so it uses jdk 1.7:

<properties>
    ...
    <jdk.version>1.7</jdk.version>
</properties>

<plugin>
    <artifactId>maven-compiler-plugin</artifactId>
        ...
        <configuration>
            <source>${jdk.version}</source>
            <target>${jdk.version}</target>
        </configuration>
</plugin>

When I execute them on the console they compile fine and the displayed version is correct:

javac -version
javac 1.7.0_55

mvn install -debug
Apache Maven 2.2.1 (rdebian-8)
Java version: 1.7.0_55
Java home: /usr/lib/jvm/java-7-openjdk-amd64/jre

However, when I do the same in a jenkins job, Maven uses the 1.6 version instead of 1.7:

javac -version
javac 1.7.0_55

mvn install -debug
Apache Maven 2.2.1 (rdebian-8)
Java version: 1.6.0_31
Java home: /usr/lib/jvm/java-6-openjdk-amd64/jre

I have also modified the maven configuration file that I use to indicate the new version, and in the Jenkins administration panel I have changed the JDK version. However, Maven is still using the 1.6 jdk.

Do you know how can I change it?

like image 592
rafaborrego Avatar asked May 14 '14 11:05

rafaborrego


1 Answers

I found the solution here. It is necessary to define the JAVA_HOME variable also in the global configuration of Jenkins. As Sudharsan explained, the steps are:

  1. Go to Manage Jenkins - Configure system

  2. Add JAVA_HOME and its path in Global Properties - Environment Variables

like image 154
rafaborrego Avatar answered Nov 02 '22 13:11

rafaborrego