IBM Support

Changing Default Version for JDK (java.version)

Troubleshooting


Problem

This document describes how to switch to a different JDK when you have multiple JDKs installed to your IBM i OS.

Resolving The Problem

 


Setting JDK for IBM Technology for JVM (R540, R610, R710, R720, R730, R740)

 The only way to use IBM Technology for JVM is by setting the JAVA_HOME environment variable.

There are three common techniques for setting JAVA_HOME:
1.
Use the ADDENVVAR CL command. For example, to add the variable to your current interactive job, enter the following on a CL command line:
Java 8 Example:
ADDENVVAR ENVVAR(JAVA_HOME) VALUE('/QOpenSys/QIBM/ProdData/JavaVM/jdk80/64bit’) LEVEL(*JOB)

Java 11 Example:
ADDENVVAR ENVVAR(JAVA_HOME) VALUE('/QOpenSys/QIBM/ProdData/JavaVM/jdk11/64bit’) LEVEL(*JOB)
Use the following if you want to set the variable at the system level:
Java 8 Example:
ADDENVVAR ENVVAR(JAVA_HOME) VALUE('/QOpenSys/QIBM/ProdData/JavaVM/jdk80/64bit') LEVEL(*SYS)
Java 11 Example:
ADDENVVAR ENVVAR(JAVA_HOME) VALUE('/QOpenSys/QIBM/ProdData/JavaVM/jdk11/64bit’) LEVEL(*SYS)

If you want to remove the JAVA_HOME variable type, use the following:
RMVENVVAR JAVA_HOME LEVEL(*JOB) - For Interactive job
RMVENVVAR JAVA_HOME LEVEL(*SYS) - System wide removal
2.
Set JAVA_HOME from within QSHELL. For example:

a. Open a Qshell session using the STRQSH command.
b. Export the variable to your process:
export -s JAVA_HOME=/QOpenSys/QIBM/ProdData/JavaVM/jdk80/64bit
To remove the JAVA_HOME environment variable from within Qshell, use the unset command. For example, use the following:
unset JAVA_HOME
3.
Use a .profile file to initialize the shell. If you would like JAVA_HOME to be set every time you start Qshell, you may create a .profile file in a user’s home directory. For example, if your i5/OS user profile is John, you would perform the following steps:
a. Create a file called .profile in /home/John.
b. Add the following text to the file:
export -s JAVA_HOME=/QOpenSys/QIBM/ProdData/JavaVM/jdk80/64bit
c. Save the file.
Java 11 JAVA_HOME is JAVA_HOME=/QOpenSys/QIBM/ProdData/JavaVM/jdk11/64bit
Note: You should not use the java.home system property to set the JDK home. This will not work on IBM i. In fact, if you attempt to set java.home in the SystemDefault.properties file, the Java product may stop working completely. The only way to change the JDK is to set JAVA_HOME as an environment variable. See the IBM Information center for more information:

http://www-01.ibm.com/support/docview.wss?uid=nas8N1011999

[{"Type":"MASTER","Line of Business":{"code":"LOB57","label":"Power"},"Business Unit":{"code":"BU058","label":"IBM Infrastructure w\/TPS"},"Product":{"code":"SWG60","label":"IBM i"},"ARM Category":[{"code":"a8m0z0000000CH5AAM","label":"Java Development Kit"}],"ARM Case Number":"","Platform":[{"code":"PF012","label":"IBM i"}],"Version":"All Versions"}]

Historical Number

19754920

Document Information

Modified date:
23 June 2022

UID

nas8N1017748