Jenkins, specifying JAVA_HOME - java

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 ?

Your JAVA_HOME variable must be set 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).

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

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.

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)

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).

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
java jenkins java-home ubuntu centos

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

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

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

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 as path and jenkins didn't complain anymore.

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

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

Related

Jenkins JRE Update

I am running a Jenkins server on Windows that is using the JRE in the Jenkins folder. The version is 1.8.0_66 but the Let's Encrypt certificate used by the Update Center is not compatible with this version, hence I need to update it.
Is there a stand-alone JRE available that I can replace the contents of this folder with, or is there a standard way of updating this JRE within Jenkins itself?
You can install Java on your local computer from here. Typically on Windows it would install it in a folder like C:\Program Files\Java\jdk1.8.0_161. Then just copy the JRE folder C:\Program Files\Java\jdk1.8.0_161\jre along with all its subfolders and files from your local computer to the JRE in the Jenkins folder (JAVA_HOME) so that you replace its contents. You can see JAVA_HOME from Jenkins System info. You can archive your old JRE installation files before that.
The second option is to install JRE on your Jenkins server directly from here. It will create a directory like this C:\Program Files\Java\jre1.8.0_161. Then you could copy this folder contents into the Jenkins_home/jre folder or the folder your Jenkins is using.
Third option is to install JRE on your Jenkins server and then change the JAVA_HOME variable so that Jenkins uses the standard folder for your operating system. More info here.
You may need to import your certificates into java keystore. See How to import a .cer certificate into a java keystore?
This is for windows users who happen to stumple upon this question (like I did). You need to have the system environment variable JAVA_HOME set.
stop jenkins service
edit in the jenkins base folder edit jenkins.xml -
<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>%BASE%\jre\bin\java</executable>
<arguments>-Xrs -Xmx256m -Dhudson.lifecycle=hudson.lifecycle.WindowsServiceLifecycle -jar "%BASE%\jenkins.war" --httpPort=8080 --webroot="%BASE%\war"</arguments>
change %BASE% to %JAVA_HOME% in "executable"
<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%\jre\bin\java</executable>
<arguments>-Xrs -Xmx256m -Dhudson.lifecycle=hudson.lifecycle.WindowsServiceLifecycle -jar "%BASE%\jenkins.war" --httpPort=8080 --webroot="%BASE%\war"</arguments>
start jenkins

Start Jenkins with JDK 8 without changing system java_home

I have Jenkins 2.46.3 LTS version that i am trying to upgrade to 2.73.3 LTS version. My current java version is 1.7. How do i install and start Jenkins with 1.8 version? I am getting the following error after i copied Jenkins war file under (/usr/lib/Jenkins) and restarted the service
$ sudo service jenkins start
Starting Jenkins Jenkins requires Java8 or later, but you are running 1.7.0_97-b02 from /app_2/java/jdk1.7.0_97/jre
java.lang.UnsupportedClassVersionError: 51.0
at Main.main(Main.java:124)
Is there any way to start Jenkins using Java 8 without changing the system classpath?
Thanks,
Ann
Set JENKINS_JAVA option in /etc/sysconfig/jenkins file.
The variable name might be different depending on your operating system and package source but the /etc/sysconfig/jenkins file is usually the configuration file for your jenkins service.
Just run the war with the new java binary:
nohup <path to your new jdk8 folder>/java -jar jenkins.war > $LOGFILE 2>&1
Not sure if JAVA_HOME is needed, but you can execute the line below in the shell, before the command above, or add to the top of init script :
export JAVA_HOME=<path to your new jdk8 folder>/java
Hope that helps.

What makes Oracle SOA Suite 12 JAR unable to recognize the JAVA_HOME?

I am trying to install Oracle SOA Suite 12 on Windows 10. I set the JAVA_HOME correctly (able to echo it), and then trying to run the JAR. It gives me the following message:
This installer must be executed using a Java Development Kit (JDK)
but C:\Program Files\Java\jre1.8.0_161 is not a valid JDK Java Home.
It seems to look for the JRE folder and by default neglecting the JAVA_HOME environment variable. I did a workaround by navigating to the JDK folder, and then running the java.exe inside the JDK folder (java.exe -jar /path/to/soasuite). It works well. I just want to know what might be the reason.
I advise you to set the properties as follow. Adapt correctly to your path in the JAVA_HOME property, and the others will follow.
JAVA_HOME := C:\java\jdk1.8.0_151
JDK_HOME := %JAVA_HOME%
JRE_HOME := %JAVA_HOME%\jre
CLASSPATH := .;%JAVA_HOME%\lib;%JAVA_HOME%\jre\lib
PATH := %JAVA_HOME%\bin;%PATH%
EDIT:
I did a workaround by navigating to the JDK folder, and then running
the java.exe inside the JDK folder (java.exe -jar /path/to/soasuite).
It works well. I just want to know what might be the reason.
This means that you are missing the change in the PATH environment.
I was not able to utilize the path variables described - did not want to restart the machine durng and install of oracle software. I was able to successfully complete the install of weblogic oracle fusion by doing the following.
RUN JAR files using command prompt due to having issues running the java installed setups for oracle12c, weblogic ,etc.
RUN command prompt as adminsitrator:
1. CHANGE DIRECTORY IN COMMAND PROMPT TO:
C:\Program Files\Java\jdk1.8.0_181\bin
RUN the command like this - pointing to the proper JAR file.
java -jar c:\oracleformssoftware\fmw_12.2.1.3.0_infrastructure.jar
This definately worked for me but please note I did finally setup the path variables instructions noted here.

GlassFish does not start

I'm starting with the Glassfish technology. I found this impediment, after having downloaded and put on disk c: the installer, I go to the windows command screen and execute the command "asadmin start-domain", but my answer is
-jar: illegal argument.
I have already configured the JAVA_HOME and the route. But it does not work. Could you suggest something?
The version of the Glassfish Platform is 4.1.2
The Java Development Kit version is 8
Command line
asadmin start-domain
Path JAVA_HOME
In addition to Ramanlfc's comment, you will also need to check your environment variables. On Windows, you will need to add your JDK's binaries location (%JAVA_HOME%) to the system path in order to start GlassFish:
https://www.mkyong.com/java/how-to-set-java_home-on-windows-10/

JAVA_HOME does not point to the JDK

I am trying to follow a tutorial about how to use ant to build and run your application. I've followed all the steps and have created the build file, but when I try to run ant it gives me this error.
BUILD FAILED
/home/bilal/tmp/ant/build.xml:19: Unable to find a javac compiler;
com.sun.tools.javac.Main is not on the classpath.
Perhaps JAVA_HOME does not point to the JDK.
It is currently set to "/usr/lib/jvm/java-6-openjdk/jre"
Any ideas how to resolve this issue ?
Make JAVA_HOME variable point to a jdk installation, not jre.
You are referencing the runtime environment, not the development kit - it can't find the compiler because its not there.
From the line you posted, which states you have open-jdk you can just remove the jre at end:
export JAVA_HOME='/usr/lib/jvm/java-6-openjdk/'
You installed java...
apt-get install default-jre
But not the JDK...
apt-get install default-jdk
This is by design. You cannot use ant's java.home (which is a java.lang.System property) interchangeably with how JAVA_HOME is set in the OS environment. You are probably trying to assert the location of the Java compiler with a fundamentally different value from a different property layer -- i.e. java.home (from Ant's Java internals) points to the Java Runtime Environment at <any_installed_java_pointed_to_by_ant>/jre while JDK_HOME (from the OS environment) is usually set to <DOWNLOADED_AND_INSTALLED_JAVA_DEVELOPMENT_KIT>.
See my question and answer here for more details: Where does Ant set its 'java.home' (and is it wrong) and is it supposed to append '/jre'?
The solution is to access the system environment property within Ant by using ${env.JAVA_HOME}. Specify which java to use explicitly in the Javac Task by setting the executable property to the javac path and the fork property to yes (see Ant's Javac Task Documentation). That way, it doesn't matter what Java environment Ant is running inside, the compiler is always clearly specified!
I know this question is old but the accepted answer does not work anymore and since this is the fist link on google search i'll tell how i solved this problem.
for eclipse using ubuntu:
go to Window->Preferences->Ant->Runtime->Select Ant_Home_Entries and click on add external jars then find in file explorer where your jdk is (default is in /usr/lib/jvm/) and in the lib folder of your jdk you will find the tool.jar. select this one and click apply.
try to build your project and things should work!
note: i hadn't used ant for a long time but needed it for ycsb couchbase workload generator (http://www.couchbase.com/wiki/display/couchbase/Load+Generator+Setup) if anyone is/was stuck on this.
It looks like you are currently pointing JAVA_HOME to /usr/lib/jvm/java-6-openjdk/jre which appears to be a JRE not a JDK. Try setting JAVA_HOME to /usr/lib/jvm/java-6-openjdk.
The JRE does not contain the Java compiler, only the JDK (Java Developer Kit) contains it.
I am using Windows 7 and have struggled with the same issue. I fixed it by changing my environment variables.
To change your environment variables click here
I added ";%JAVA_HOME%/bin" to the end of paths variable and added a new "JAVA_HOME" variable and set its value to the location of my JDK "C:\Program Files\Java\jdk1.8.0_11". After that I restarted my Node.js command prompt and it worked.
Please note you JDK directory may be different then mine. Also depending on your setup, you may need to restart you computer after setting the environment variables.
The JAVA_HOME you have above only points to the JRE, which does not contain the compiler. Set your JAVA_HOME to
/usr/lib/jvm/java-6-openjdk
...and try again.
I had a similar problem and it turned out the issue was having both versions 6 & 7 of OpenJDK. The answer comes from r-senior on ubuntu forums (http://ubuntuforums.org/showthread.php?t=1977619) --- just uninstall version 6:
sudo apt-get remove openjdk-6-*
make sure that JAVA_HOME and CLASSPATH aren't set to anything since that isn't actually the problem.
for centos yum -y install java-1.7.0-openjdk-devel.x86_64
and update JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk.x86-64
I just copied tools.jar file from JDK\lib folder to JRE\lib folder. Since then it worked like a champ.
Experienced this issue when trying to run the android emulator with Meteor 1.0 on elementary OS Luna (based on Ubuntu 12.04 LTS sources).
openjdk-6-jdk was installed, as well as the jre. In the end, not expecting any success, I tried:
sudo apt-get remove openjdk-6-*
this resulted in fully expected errors, so I followed up with
sudo apt-get install openjdk-6-jdk
and things worked. Go figure.
On Ubuntu 14.04, I found two parts to solving the problem:
Remove /jre from the environment variable. For me: export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/
Install the JDK as well as the JRE: sudo apt-get install default-jdk
Once you update the JAVA_HOME path as stated in the answer, you should do this:
$source ~/.bashrc
This will refresh bashrc show the updated path in $JAVA_HOME when you check again.
Execute:
$ export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.141-3.b16.el6_9.x86_64
and set operating system environment:
vi /etc/environment
Then follow these steps:
Press i
Paste
JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.141-3.b16.el6_9.x86_64
Press esc
Press :wq
I met this issue in rhel, my "JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk"(which is a symbolic link), and ant complains.
MY solution for this is to use the real jdk path in JAVA_HOME, like:
JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.161-0.b14.el7_4.x86_64
It works for me.
Under Jenkins it complains like :
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.191.b12-1.el7_6.x86_64/ doesn’t look like a JDK directory
Reason : Unable to found any Dev Kit for JDK.
Solution:
Please make sure to install openjdk-devel package as well along with your JDK-1.8* version and reexport with : # source ~/.bash_profile

Categories