How To Set The Java Path In Mac For Jenkins



  • Status:Open(View Workflow)
  • Resolution: Unresolved
  • Labels:

Hudson uses the configured JDK for a maven build but does not set the JAVA_HOME property. So if you try to make a release the prepare is executed against the configured jdk but the perform is executed against the default JDK.

How To Set The Java Path In Mac For Jenkins

We have a couple of builds which depends on the IBM JDK. We have configured whe jobs appropriately and it is working for snapshot builds. When running a release build the JDK tomcat is running on (Sun JDK) is used instead.

When we set the JAVA_HOME explicitely in the job it works. But this is a mess as we have to enter the full path to the jdk (and this is not the same on all slaves).

  • Defining a JAVAHOME environment variable in the Jenkins environment will be enough: export JAVAHOME = /path/to/JDK9. If you run Jenkins in a container, just define JAVAHOME in the docker run command.
  • Open the Jenkins dashboard. Go to Manage Jenkins. Go to Global Tool Configuration to configure tools, their locations, and automatic installers. Go to the JDK section.
  • Provide JAVAHOME path to the JDK folder on the client/slave such as C:Progra2Javajdk1.7.067 where Proga2 resolves to Program Files (x86) Show Damon Overboe added a comment - 2014-08-14 18:48 - edited On Jenkins 1.575, working against Windows Server 2012, setting the JDK in Jenkins provides the option to input the JAVAHOME variable,.
  • We are assuming Java 1.7.0.60 as installed version for this tutorial. Step 2 - Set JAVA Environment. Set the JAVAHOME environment variable to point to the base directory location where Java is installed on your machine.

Now, in the Jenkins dashboard (Home screen) click on manage Jenkins from the left-hand side menu. Click on 'Global Tool Configuration' option. To configure Java, click on 'Add JDK' button in the JDK section.Give a Name and JAVAHOME path, or check on install automatically checkbox. And now, to configure Maven, click on 'Add Maven' button in the Maven section, give any Name and MAVENHOME path.

Hudson should set JAVA_HOME for the current build or - at least - provide a variable which holds the path to the configured JDK.

This a blocking issue at our site!

is related to

JENKINS-7886Use the JDK configured for the job

  • Resolved
Hide
Vincent Latombe added a comment -

Hello,
have you checked http://wiki.jenkins-ci.org/display/JENKINS/Tool+Environment+Plugin ?

Show
Vincent Latombe added a comment - Hello, have you checked http://wiki.jenkins-ci.org/display/JENKINS/Tool+Environment+Plugin ?
Hide
micha4311 added a comment -

Thanks for the suggestion. I saw this plugin on my research but found that it is not the best way as it does not export JAVA_HOME but something like SUN_1_6_HOME - so we need an additional config like exporting a parameter 'JAVA_HOME' with the value 'SUN_1_6_HOME'.

How To Set The Java Path In Mac For Jenkins Download

I will check if it could be used as a workaround Indeed it is better as we do not need to know the full path (and only need to know the transformation algorithm from the JDKs name).

For a long term solution the JAVA_HOME should be exported as it does not make any sense to NOT export it.

Show
micha4311 added a comment - Thanks for the suggestion. I saw this plugin on my research but found that it is not the best way as it does not export JAVA_HOME but something like SUN_1_6_HOME - so we need an additional config like exporting a parameter 'JAVA_HOME' with the value 'SUN_1_6_HOME'. I will check if it could be used as a workaround Indeed it is better as we do not need to know the full path (and only need to know the transformation algorithm from the JDKs name). For a long term solution the JAVA_HOME should be exported as it does not make any sense to NOT export it.
Hide
micha4311 added a comment -

I tried the tool environment plugin but failed to set JAVA_HOME for the calling process. It seems that I cannot use the exporter SUN_1_6_HOME variable as a build parameter. Additionally everyone doing a manual build would be in need to 'skip' the parameters page

Show
micha4311 added a comment - I tried the tool environment plugin but failed to set JAVA_HOME for the calling process. It seems that I cannot use the exporter SUN_1_6_HOME variable as a build parameter. Additionally everyone doing a manual build would be in need to 'skip' the parameters page
Hide
micha4311 added a comment -

I found out a little more and it seems to be a little more complex than originally thought.

Hudson DOES define the used JDK as JAVA_HOME. This is working when the build runs on the master.

How To Set The Java Path In Mac For Jenkins

When running on a slave (we use the ssh-slaves-plugin) this Environment-setting is lost. On the slave-configuration-page we define an environment variable JAVA_HOME (needed so that hudson is able to start the slave as java is not on the path) and every build on the slaves uses this variable.

Show
micha4311 added a comment - I found out a little more and it seems to be a little more complex than originally thought. Hudson DOES define the used JDK as JAVA_HOME. This is working when the build runs on the master. When running on a slave (we use the ssh-slaves-plugin) this Environment-setting is lost. On the slave-configuration-page we define an environment variable JAVA_HOME (needed so that hudson is able to start the slave as java is not on the path) and every build on the slaves uses this variable.
Hide
micha4311 added a comment -

We currently did a workaround with a combination of Tool Environment Plugin and SetEnv Plugin:

  • let Tool Environment Plugin export the java-Home (uses something like SUN_1_6_HOME)
  • let SetEnv export JAVA_HOME=${SUN_1_6_HOME}

it works for us as the job configs are created automatically. Otherwise it would be ugly as you have to define the used jdk twice which is error prone

Show
micha4311 added a comment - We currently did a workaround with a combination of Tool Environment Plugin and SetEnv Plugin: let Tool Environment Plugin export the java-Home (uses something like SUN_1_6_HOME) let SetEnv export JAVA_HOME=${SUN_1_6_HOME} it works for us as the job configs are created automatically. Otherwise it would be ugly as you have to define the used jdk twice which is error prone
Hide
Damon Overboe added a comment - - edited

On Jenkins 1.575, working against Windows Server 2012, setting the JDK in Jenkins provides the option to input the JAVA_HOME variable, and that worked around the issue for me.

How to set the java path in mac for jenkins download

This might be what you were referring to as having it set twice, but given that it seems to completely ignore JAVA_HOME on the clients (even though it reports that correctly with the script console) it doesn't seem to cause any issues.

Here were my steps:

  1. Manage Jenkins
  2. Configure System
  3. Scroll to JDK installations
  4. Add JDK Installation
  5. Provide JAVA_HOME path to the JDK folder on the client/slave
    such as C:Progra~2Javajdk1.7.0_67where Proga~2 resolves to Program Files (x86)
Show
Damon Overboe added a comment - - edited On Jenkins 1.575, working against Windows Server 2012, setting the JDK in Jenkins provides the option to input the JAVA_HOME variable, and that worked around the issue for me. This might be what you were referring to as having it set twice, but given that it seems to completely ignore JAVA_HOME on the clients (even though it reports that correctly with the script console) it doesn't seem to cause any issues. Here were my steps: Manage Jenkins Configure System Scroll to JDK installations Add JDK Installation Provide JAVA_HOME path to the JDK folder on the client/slave such as C:Progra~2Javajdk1.7.0_67 where Proga~2 resolves to Program Files (x86)
Votes:
2Vote for this issue
Watchers:
6Start watching this issue

Java is a very popular programming language which provides a different component in order to run, develop Java applications. JRE or Java Runtime Environment is used to run Java application. JDK or Java Development Kit is used to develop Java applications. In this tutorial, we will learn how to set up Java, JRE, and JDK operating system path variables in order to work properly.

Before starting the configuration we have to locate the JRE or JDK path. JRE or JDK generally installed on the Program Files or Program Files(x86) directory under the Java directory like below.

How To Set Java Path

and under the Java directory the JDK is residing.

How To Set The Java Path In Mac For Jenkins Free

Now we have learned the path of the Java, JRE or JDK installation. We can set this path as Java HOME_PATH environment variable. We will open the computer properties with by running sysdm.cpl in the Run menu like below. We can also open it from the File Explorer -> Computer -> Right Click.

In the system properties, we will navigate to the Advanced tab which provides the Environment Variables button like below.

Below we can see the environment variables menu where we will create the JAVA_HOME system variable and set the path accordingly. We click to the New in order to create a new system variable.

Here we will set the Variable Name as JAVA_HOME and the Variable Value the path or Java, JRE or JDK which is C:Program FilesJavajdk-12 in this example. Then we will click OK.

If we want to run java.exe or similar executables provided by JRE or JDK we have to add the path of Java in the Path variable like below. We select the system variable named Path and click to the Edit.

Here we click to New which will add a new line to the existing values.

How To Set The Java Path In Mac For Jenkins Full

Here we will set the bin folder path which is C:Program FilesJavajdk-12bin in this example.

Then we will click OK and OK in the environment variables screen which will save and activated new path configuration.

We can check the new path configuration simply opening a new command line interface MS-DOS. Then just type java -version which will execute java.exe with the -version option. We can see the current java binary version by running it.