[java] 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

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.

it is also failing to pick up my maven install.

Am I missing something obvious ?

This question is related to java ubuntu jenkins java-home

The answer is


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


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

as path and jenkins didn't complain anymore.


I just wanted to add a solution for Windows machines.

  • Windows Server 2008 R2 Standard, SP1
  • Jenkins 2.89.4
  • Java version 8.171

Symptom: Jenkins service starts and immediately stops.
Jenkins.wrapper.log has a line indicating the incorrect path to Java:

- Starting C:\Program Files\Java\jre1.8.0_141\bin\java -Xrs -Xmx6g -Dhudson.lifecycle=hudson.lifecycle.WindowsServiceLifecycle -jar "C:\Program Files (x86)\Jenkins\jenkins.war" --httpPort=8080 --webroot="C:\Program Files (x86)\Jenkins\war"

The fix: Jenkins has the path hard-coded in jenkins.xml. Change the path to the new Java location.

<env name="JENKINS_HOME" value="%BASE%"/>
<!--
if you'd like to run Jenkins with a specific version of Java, specify a full path to java.exe.
The following value assumes that you have java in your PATH.
-->
<executable>C:\Program Files\Java\jre1.8.0_171\bin\java</executable>
<arguments>-Xrs -Xmx256m -Dhudson.lifecycle=hudson.lifecycle.WindowsServiceLifecycle -jar "%BASE%\jenkins.war" --httpPort=8080 --webroot="%BASE%\war"</arguments>

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.

<env name="JENKINS_HOME" value="%BASE%"/>
<!--
if you'd like to run Jenkins with a specific version of Java, specify a full path to java.exe.
The following value assumes that you have java in your PATH.
-->
<executable>%JAVA_HOME%\bin\java</executable>
<arguments>-Xrs -Xmx256m -Dhudson.lifecycle=hudson.lifecycle.WindowsServiceLifecycle -jar "%BASE%\jenkins.war" --httpPort=8080 --webroot="%BASE%\war"</arguments>

openjdk-6 is a Java runtime, not a JDK (development kit which contains javac, for example). Install 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).


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

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.


For those of you coming to this issue and have access to configure your Jenkins Agents, you can set the JAVA_HOME from the Jenkins > Nodes > "the agent name" > Configure page:

Setting "per agent" environment variables


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.


I was facing the same issue and for me downgrading the JAVA_HOME from jdk12 was not the plausible option like said in the answer. So I did a trial and error experiment and I got the Jenkins running without even downgrading the version of JAVA_HOME.

Steps:

  • open configuration $ sudo vi /etc/init.d/jenkins
  • Comment following line:
 #JAVA=`type -p java`
  • Introduced the line mentioned below. (Note: Insert the specific path of JDK in your machine.)
 JAVA=`type -p /usr/lib/jdk8/bin/java`
  • Reload systemd manager configuration: $ sudo systemctl daemon-reload
  • Start Jenkins service: $ sudo systemctl start jenkins
    ? jenkins.service - LSB: Start Jenkins at boot time
       Loaded: loaded (/etc/init.d/jenkins; generated)
       Active: active (exited) since Sun 2020-05-31 21:05:30 CEST; 9min ago
         Docs: man:systemd-sysv-generator(8)
      Process: 9055 ExecStart=/etc/init.d/jenkins start (code=exited, status=0/SUCCESS)
    

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


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


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 although I believe they are correct for ubuntu also.

Modify /etc/sysconfig/jenkins and set variable JENKINS_JAVA_CMD="/<your desired jvm>/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


In Jenkins try setting JAVA_HOME to /usr/lib/jvm/java-6-openjdk


Examples related to java

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How much should a function trust another function How to implement a simple scenario the OO way Two constructors How do I get some variable from another class in Java? this in equals method How to split a string in two and store it in a field How to do perspective fixing? String index out of range: 4 My eclipse won't open, i download the bundle pack it keeps saying error log

Examples related to ubuntu

grep's at sign caught as whitespace "E: Unable to locate package python-pip" on Ubuntu 18.04 How to Install pip for python 3.7 on Ubuntu 18? "Repository does not have a release file" error ping: google.com: Temporary failure in name resolution How to install JDK 11 under Ubuntu? How to upgrade Python version to 3.7? Issue in installing php7.2-mcrypt Install Qt on Ubuntu Failed to start mongod.service: Unit mongod.service not found

Examples related to jenkins

Maven dependencies are failing with a 501 error Jenkins pipeline how to change to another folder Docker: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock groovy.lang.MissingPropertyException: No such property: jenkins for class: groovy.lang.Binding How to solve npm install throwing fsevents warning on non-MAC OS? Run bash command on jenkins pipeline Try-catch block in Jenkins pipeline script How to print a Groovy variable in Jenkins? Jenkins pipeline if else not working Error "The input device is not a TTY"

Examples related to java-home

Set ANDROID_HOME environment variable in mac Error: JAVA_HOME is not defined correctly executing maven How to set JAVA_HOME in Linux for all users Android Studio error: "Environment variable does not point to a valid JVM installation" Installing Android Studio, does not point to a valid JVM installation error How can I change Mac OS's default Java VM returned from /usr/libexec/java_home How to set JAVA_HOME path on Ubuntu? Where is the Java SDK folder in my computer? Ubuntu 12.04 How to set JAVA_HOME in Mac permanently? How to set CATALINA_HOME variable in windows 7?