Recommendations and requirements for calling Java from RPG - Support

Recommendations and requirements for calling Java from RPG

From Support

Jump to: navigation, search
If you have a question or seek clarification, please call Technical Support.

Problem:

Why does my RPG program pick up the wrong JDK when calling Java?

I want to use JDK 1.4, and created a SystemDefault.properties file in my user.home path which has a java.version=1.4, but when I check the active JDK called by my RPG program, it says 1.3. Why? Where is it getting this?

Solution:

The method that RPG uses to start the JVM is the Invocation API. This is the same API that is used to start a JVM to make aJNI call. When a JVM is started in this way, Java ignores the java.version property. And so the default JVM (see below) isused.

You can use either of the following approaches to explicitly define which JDK is to be used:

Start the JVM explicitly by calling the Invocation API JNI_CreateJavaVM, specifying the -Djava.version=1.4 option. Do this prior to invoking any Java classes in the job.

Set the desired values in the QIBM_RPG_JAVA_PROPERTIES environment variable before calling any Java routines. For example:

   ADDENVVAR ENVVAR(QIBM_RPG_JAVA_PROPERTIES) VALUE('-Djava.version=1.4;-Dos400.stderr=file:/home/mydir/temp.out;')

Note: To use the above environment variable, you will have to install the PTF which corresponds to your OS/400 release level:

   V5R1M0 SI10069
   V5R2M0 SI10631
   V5R3M0 base - See What's new doc here: http://tinyurl.com/54ntm

The properties are defined in a mannar similar to defining them on the java command from the QShell command line, with the -D option. And the property names and values that follow the -D are defined in the same mannar as if they were specified in a SystemDefault.properties file.

Please note that the RPG compiler will automatically retrieve the CLASSPATH environment variable (if one is defined) and create a java.class.path property to use in starting the JVM. So, it would be best to have the CLASSPATH environment variable defined prior to invoking the first Java class in the job, and to NOT specify a java.class.path within the QIBM_RPG_JAVA_PROPERTIES value. This will avoid any confusion over where the classpath that will actually be used is being defined.

Additional information:

How to use the QIBM_RPG_JAVA_PROPERTIES environment variable:

How to check which JDK is really running:

  • You can check the JDK that is running by performing a DMPJVM on the job running the JDK, or you can add the following line to your Java program:
   String versionID = System.getProperty("java.version");

Documentation on the JNI_CreateJavaVM API:

http://publib.boulder.ibm.com/iseries/v5r2/ic2924/info/rzaha/invofunc.htm

Which JDK will be used as the default JDK when java.version is not defined?

http://publib.boulder.ibm.com/iseries/v5r2/ic2924/index.htm?info/rzaha/multjdk.htm

If you install more than one JDK, the following order of precedence determines the default JDK, the first in the list that is installed will be the one used when no java.version is defined:

  • Option 5 (1.3)
  • Option 3 (1.2)
  • Option 6 (1.4)
  • Option 4 (1.1.8)
Personal tools