Changing default JDK for a job...

3,366 views
Skip to first unread message

Jeff

unread,
Dec 28, 2012, 12:25:44 PM12/28/12
to jenkins...@googlegroups.com
I have a brand new Jenkins master + slave running on top of the latest JDK 1.7.0_u10.

I've configured multiple JDK versions in Jenkins (with auto installers from Oracle), including JDK 1.6.0_u37.

I have one Maven job that uses the wsgen/wsimport commands to generate WSDL and client files that works fine when running in JDK 1.6, but fails with JDK 1.7.

I have set the job to use JDK 1.6, but it still executes the maven command against the default JDK 1.7. 

I thought that by configuring the job with a specific JDK, that is what it would use, but that doesn't seem to be the case.

How do I force the job (maven command) to run using the correct JDK?

--
I ♥ DropBox !! 

Eric Pyle

unread,
Dec 28, 2012, 12:40:54 PM12/28/12
to jenkins...@googlegroups.com

Jeff

unread,
Dec 28, 2012, 12:51:53 PM12/28/12
to jenkins...@googlegroups.com
Won't that will just cause clutter in the POM that will affect every developer and every environment?

Seems like it would be cleaner to just allow me to tell Jenkins to run the job using the correct JDK that was specifically defined in the job.

My questions:
  • Why doesn't job execution honor the JDK setting?
  • Is there a way to force a new value for JAVA_HOME for a specific job?

Eric Pyle

unread,
Dec 28, 2012, 1:04:32 PM12/28/12
to jenkins...@googlegroups.com
Your first question is a Maven issue - I could only speculate about it. For the second question - yes, in the Build Environment section of the job configuration you can set environment variables for the job.

Eric

Jeff

unread,
Dec 28, 2012, 1:26:59 PM12/28/12
to jenkins...@googlegroups.com
I can't find anything in the "Build Environment" section that allows this.  The check boxes I see are:

Build Environment
Help for feature: Copy files into the job's workspace before building
Help for feature: Execute shell script on remote host using ssh

In the "Build" section, I can set MAVEN_OPTS but by this time, the "mvn" command would have already been launched using whatever the default java install is, or am I missing something?

I do have the "JDK" set to the correct value (Sun JDK 6u37) for this job.  

JDK
JDK to be used for this project

Why isn't the job using it?  Isn't that what it's for?

Eric Pyle

unread,
Dec 28, 2012, 1:37:40 PM12/28/12
to jenkins...@googlegroups.com
Looks like you need the Setenv plugin to get that option.


On 12/28/2012 1:26 PM, Jeff wrote:
I can't find anything in the "Build Environment" section that allows this.  The check boxes I see are:

Build Environment
Help for feature:
                        Copy files into the job's workspace before
                        building



Help for feature:
                        Execute shell script on remote host using ssh




In the "Build" section, I can set MAVEN_OPTS but by this time, the "mvn" command would have already been launched using whatever the default java install is, or am I missing something?

I do have the "JDK" set to the correct value (Sun JDK 6u37) for this job.  

JDK

Jeff

unread,
Dec 28, 2012, 3:04:43 PM12/28/12
to jenkins...@googlegroups.com
So it's now working with no changes that I can tell other than possibly restarting Jenkins.


I went to install the Setenv plugin, found it was deprecated in favor of the "Environment Inject" plugin then noticed a new version of Jenkins (1.495) so I installed the Environment Inject plugin, downloaded and deployed the new Jenkins version and amongst the changes ended up restarting Jenkins.


When I went to configure the EnvInject plugin, I remembered the maven command "help:system" that dumps the current environment so I added that to the maven command line to verify the current settings and noticed that JAVA_HOME was pointing to the correct JDK and the build succeeded.  I then removed the EnvInject plugin, restarted Jenkins and the build still worked.


I noticed that the difference between the failed build and the good build included this line:

BAD BUILD:

[MyService (trunk)] $ java -Xmx512m -XX:MaxPermSize=128m -cp /home/adminuser/.jenkins-slave/maven3-agent.jar:/home/adminuser/.jenkins-slave/tools/Maven/Maven_3.0.4/boot/plexus-classworlds-2.4.jar org.jvnet.hudson.maven3.agent.Maven3Main /home/adminuser/.jenkins-slave/tools/Maven/Maven_3.0.4 /home/adminuser/.jenkins-slave/slave.jar /home/adminuser/.jenkins-slave/maven3-interceptor.jar 39025


GOOD BUILD:
[MyService (trunk)] $ /home/adminuser/.jenkins-slave/tools/hudson.model.JDK/Sun_JDK_6u37/bin/java -Xmx512m -XX:MaxPermSize=128m -cp /home/adminuser/.jenkins-slave/maven3-agent.jar:/home/adminuser/.jenkins-slave/tools/hudson.tasks.Maven_MavenInstallation/Maven_3.0.4/boot/plexus-classworlds-2.4.jar org.jvnet.hudson.maven3.agent.Maven3Main /home/adminuser/.jenkins-slave/tools/hudson.tasks.Maven_MavenInstallation/Maven_3.0.4 /home/adminuser/.jenkins-slave/slave.jar /home/adminuser/.jenkins-slave/maven3-interceptor.jar 52348


I don't understand why it started using the right JDK other than the restart (or update) forced something.


Thanks for the help.  Next time I'll restart Jenkins before freaking out! :-)
Reply all
Reply to author
Forward
0 new messages