tags:

views:

2983

answers:

5

I have a number of projects running on a Hudson slave. I'd like one of them to run Ant under Java6, rather than the default (which is Java5 in my environment).

In the project configuration view, I was hoping to find either:

  • An explicit option allowing me to set a custom JDK location to use for this project.
  • A way to set custom environment variables for this project, which would allow me to set JAVA_HOME to the JDK6 location. The would make Ant pick up and run on Java6 as desired.

Is there a way to do either of the above? If one of those facilities is available, I can't see how to access it. I'm running on Hudson 1.285.

I would rather avoid using an "execute shell" operation instead of the "invoke Ant" operation if possible: my slave is on z/OS and Hudson doesn't seem to create the temporary shell scripts properly on this platform (probably an encoding issue).

A: 

A way to set custom environment variables for this project, which would allow me to set JAVA_HOME to the JDK6 location. The would make Ant pick up and run on Java6 as desired.

When configuring the Build steps for Ant, under "Invoke Ant", if you click "Advanced", you can set custom Java options. The on-screen help says:

If your build requires a custom ANT_OPTS, specify it here. Typically this may be used to specify java memory limits to use, for example -Xmx512m. Note that other Ant options (such as -lib) should go to the "Ant targets" field.

I have a feeling this won't work for the JDK to run under, however.

Have you configured multiple JDK installations for this Hudson instance under Manage Hudson / Configure System?

matt b
Your feeling is correct: ANT_OPTS if for custom JVM options to pass to the JDK, and does not affect which JDK to use.However, I did not know about the Configure System view which allows multiple JDK installations. Not sure how this will work for slaves but I'll take a look - thanks!
rewbs
Having had a closer look, it seems the JDKs under Manage Hudson -> Configuration System are for JDKs on the master only, not the slaves. Am I missing something - is there a way to set multiple JDKs on a slave? There's no JDK option in the "Configure Node" view on Hudson 1.285.
rewbs
+6  A: 

We have both Java 5 and Java 6 configured for use in our Hudson instance.

Under Manage Hudson -> Configuration System you can add a number of JDKs and specify the path for JAVA_HOME. In the configuration for each job you then selected which JDK you would like that job to run on.

Mark
See second comment on previous answer - it seems this option allows for multiple JDKs on the master, but not on slaves/nodes.
rewbs
Missed that it was a slave. I have only ever used Hudson as a master so can't offer any insight there.
Mark
A: 

Hi,

you can use like this.

in batch command window intially u can set the variable name JAVA_HOME, Assign this custom variable name to PATH variable. then u can call an ant script to choose specific file.

Example:

set JAVA_HOME=C:/java/jdk1.6.1

PATH=%JAVA_HOME%/bin;%PATH%

ant build.xml

The question states 'I would rather avoid using an "execute shell" operation' which is what you are suggesting here.
Michael Donohue
+2  A: 

It turns out that if you make the build parametrised, any string parameters you add become environment variables. With this approach, it is possible to set any environment variable for the build, including JAVA_HOME, which is picked up by Ant.

So the best solution for me was:

  1. In the job configuration page Tick "This build is parameterized"
  2. Add an new String parameter called JAVA_HOME and with the default value set to the JDK location

It's not obvious that build string parameters become environment variables, but once you know that they do, it's easy to set the JDK this way.

The developers on the Hudson mailing list recommended another approach using the master JDK configurations and overrides in the node configurations... but just setting the JAVA_HOME env var seems way easier to me.

rewbs
A: 

Have a look at the Setenv Plugin. There you can set Variables like JAVA_HOME=C:/java/jdk1.6.1 PATH=%JAVA_HOME%/bin;%PATH%

johannes