Reputation: 600
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?
Upvotes: 5
Views: 10042
Reputation: 600
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:
Go to Manage Jenkins - Configure system
Add JAVA_HOME and its path in Global Properties - Environment Variables
Upvotes: 4
Reputation: 43
Had a similar problem when changing Jenkins jobs from JDK 1.6 to JDK 1.8. I deleted the JDK1.6 entry from "Manage Jenkins/Configure System", leaving only JDK1.8. I expected jobs would begin using JDK1.8 but they didn't. I checked the jobs and they didn't have any JDK assignment. Restarting Jenkins didn't help either.
In the end, I noticed that by just re-Saving a job, it subsequently started using the correct JDK1.8.
(Jenkins ver. 1.602)
Upvotes: 3