可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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).
回答1:
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.
回答2:
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:
- In the job configuration page Tick "This build is parameterized"
- 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.
回答3:
We managed this problem by using two different Java Hudson Nodes. One for Java 6 and one for Java 7. Then we assigned the Jobs to the different Nodes according to there needs.
回答4:
Individual slave agents can be configured to use specific JDKs on the system you run them on.
Manage Nodes > Slave > Configure > Environment Variables
For example
Name: JAVA_HOME Value: C:\Program Files (x86)\Java\jdk1.6.0_45\
回答5:
The best way is,
- Install all required JDKs to your system.
- Add those to jenkins under JDK title in configuration page.
- Install Maven Info plugin to jenkins
- Restart jenkins
- Go to your job configuration page.
- Select required JDK from the JDK combo box appear under Maven Info Plugin Configuration
- Build it
- Enjoy!!!
回答6:
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
?
回答7:
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
回答8:
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%
回答9:
I had a problem where the installed JDK was JDK 8 whereas I wanted Jenkins to use JDK 7 . So , after installing JDK 7 on the Jenkins build box ,
I added the JDK path to jenkins Configurations :
Jenkins -> Manage Jenkins -> Configure system -> JDK -> Add JDK name and Path
Also , Edit jenkins-runner.sh: Add the line:
export JAVA_HOME=""
Change the last two lines to read:
echo "/bin/java" $javaArgs -jar "$war" $args
exec "/bin/java" $javaArgs -jar "$war" $args