Search code examples
javaibm-midrange

Check java version programmatically on IBM i using CL or RPGLE


I have a situation where I have to check the java version on IBM i is equal to 1.8.

In my CL program there is a call of RUNJVA which runs a jar file which is dependent on java 1.8. I want to run that command only if IBM i machine has Java 1.8.

There are many ways on IBM i to see java version but to check version programmatically I need version information in a variable somehow.

One approach is to run command

RUNJVA CLASS(*VERSION) OUTPUT(*PRINT)

and read version from spool file. However this approach should work but I am looking for more seamless approach. Also reading spool file for information doesn't seems to be a good approach


Solution

  • I'm not sure if this is considered elegant or not, but you won't have to deal with a spool file at least. I wrote the output of java -version to a data area which you could then pick up:

    Create a data area to hold the value of the first row of the java_version file. You could add these into your CL:

    QSH CMD('java -version 2> /some/IFSdir/java_version')

    QSH CMD('head -n 1 /some/IFSdir/java_version | datarea -w /qsys.lib/doug .lib/testing.dtaara')

    Then just grab the data area into a variable and evaluate there.