Jenkins, specifying JAVA_HOME

Multi tool use


Jenkins, specifying JAVA_HOME
I installed openjdk-6-jdk on my ubuntu box using apt-get.
In system info jenkins is telling me Java.Home is /usr/lib/jvm/java-6-openjdk/jre
/usr/lib/jvm/java-6-openjdk/jre
However when I specify that directory as JAVA_HOME
in Jenkins : "configure system", it returns error message saying that directory does not look like a jdk directory.
JAVA_HOME
it is also failing to pick up my maven install.
Am I missing something obvious ?
12 Answers
12
Your JAVA_HOME variable must be setted to /usr/lib/jvm/java-6-openjdk and it must be available for the user that starts Jenkins.
From Kyle Strand comment:
As of April 2015 (I think), Jenkins requires Java7. Also note that the java binary path (JAVA) must be set to the correct version if the system default is still Java 6. Finally, for anyone wondering where these variables are set, it's in a config file listed with the installation instructions on the Jenkins webpage (e.g. for Debian it's /etc/default/jenkins).
JAVA
/etc/default/jenkins
On CentOS 6.x and Redhat 6.x systems, the openjdk-devel package contains the jdk. It's sensible enough if you are familiar with the -devel pattern used in RedHat, but confusing if you're looking for a jdk package that conforms to java naming standards.
Using Jenkins 2 (2.3.2 in my case), the right way seems to insert the following into your pipeline file:
env.JAVA_HOME="${tool 'jdk1.8.0_111'}"
env.PATH="${env.JAVA_HOME}/bin:${env.PATH}"
"jdk1.8.0_111" beeing the name of the java configuration initially registered into Jenkins
openjdk-6
is a Java runtime, not a JDK (development kit which contains javac
, for example). Install openjdk-6-jdk
.
openjdk-6
javac
openjdk-6-jdk
Maven also needs the JDK.
[EDIT] When the JDK is installed, use /usr/lib/jvm/java-6-openjdk
for JAVA_HOME
(i.e. without the jre
part).
/usr/lib/jvm/java-6-openjdk
JAVA_HOME
jre
that was a typo in the question, I installed the full jdk (javac works). Also mvn works outside of jenkins.
– NimChimpsky
Nov 18 '11 at 16:40
At first I thought "oh, c'mon, there is a needed jdk folder there", but a suggested installation probably helped as I didn't have all the needed jdk stuff.
– John Doe
Jun 19 '12 at 20:43
In case anyone has similar problems, I used the default sudo apt-get installs for the relevant packages and here are the correct settings:
JAVA_HOME=/usr/lib/jvm/java-7-openjdk-i386
and
MAVEN_HOME=/usr/share/maven2
I just wanted to add a solution for Windows machines.
Symptom: Jenkins service starts and immediately stops.Jenkins.wrapper.log
has a line indicating the incorrect path to Java:
Jenkins.wrapper.log
- Starting C:Program FilesJavajre1.8.0_141binjava -Xrs -Xmx6g -Dhudson.lifecycle=hudson.lifecycle.WindowsServiceLifecycle -jar "C:Program Files (x86)Jenkinsjenkins.war" --httpPort=8080 --webroot="C:Program Files (x86)Jenkinswar"
The fix: Jenkins has the path hard-coded in jenkins.xml
. Change the path to the new Java location.
jenkins.xml
You can also use Windows Environment Variables, but I wasn't successful with that and I don't think the Java installer updates those, so you'd need to update that by hand every time anyway.
In Jenkins try setting JAVA_HOME
to /usr/lib/jvm/java-6-openjdk
JAVA_HOME
/usr/lib/jvm/java-6-openjdk
hmmm ... what do you mean by "in jenkins?".
– jayunit100
Jun 18 '12 at 19:15
@jayunit100 I think he meant in jenkins config (/jenkins/configure), but it didn't work for me.
– John Doe
Jun 19 '12 at 20:28
Upgrading from Ubuntu 10.0.4 to 12.0.4 we got wrong footed.
We had a JDK installation configured (auto-configured?) pointing to /usr/lib/jvm/java-6-openjdk
this no longer contained a JDK,
Changing to /usr/lib/jvm/default-java fixed, and should make for a seamless java-7 upgrade.
So in answer to the question: do not specify JAVA_HOME on Ubuntu.
In Ubuntu 12.04 I had to install
openjdk-7-jdk
then javac was working !
then I could use
/usr/lib/jvm/java-7-openjdk-amd64
/usr/lib/jvm/java-7-openjdk-amd64
Download package rpm package from http://pkg.jenkins-ci.org/redhat/ you can give additional java location like I have default 1.7 java in my system but I am using /opt/jdk1.8.0_60/bin/java for jenkins. Open jenkins startup script /etc/init.d/jenkins and add additional java here, I m case I have added /opt/jdk1.8.0_60/bin/java,
Search usable Java as /usr/bin/java might not point to minimal version required by Jenkins.
See http://www.nabble.com/guinea-pigs-wanted-----Hudson-RPM-for-RedHat-Linux-td25673707.html
candidates="
/opt/jdk1.8.0_60/bin/java
This is an old thread but for more recent Jenkins versions (in my case Jenkins 2.135) that require a particular java JDK the following should help:
Note: This is for Centos 7 , other distros may have differing directory locations
Modify /etc/sysconfig/jenkins and set variable JENKINS_JAVA_CMD="//bin/java" (root access require)
Example: JENKINS_JAVA_CMD="/usr/lib/jvm/java-1.8.0-openjdk/bin/java"
Restart Jenkins (if jenkins is run as a service "sudo service jenkins stop" then "sudo service jenkins start")
The above fixed my Jenkins install not starting after I upgraded to Java 10 and Jenkins to 2.135
i saw into
Eclipse > Preferences>installed JREs > JRE Definition
i found the directory of java_home
so it's
/Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
As of April 2015 (I think), Jenkins requires Java7. Also note that the java binary path (
JAVA
) must be set to the correct version if the system default is still Java 6. Finally, for anyone wondering where these variables are set, it's in a config file listed with the installation instructions on the Jenkins webpage (e.g. for Debian it's/etc/default/jenkins
).– Kyle Strand
Jun 11 '15 at 0:49