Informing the IBM Community

A Java on IBM i Intro

0
(0)

A bit different this one. 

I was recently asked by a fellow IBM Champion to give him a quick run through on Java on the IBM i, so I thought I would write a quick article on this topic for others out there.

Installation of Java

Java has to be installed on our IBM i server before we can do anything Java related.

The first step is to install the Java licensed program, for Version 7.3 of the IBM i OS this is 5770JV1, where we need the *BASE with options 16 (32-bit version), and 17 (64-bit version).

This can be seen in the figure below.

We can see here, I have both the 32-bit and 64-bit versions installed.

To complete the installation, we need to install the latest Java group PTFs.  For my version of IBM i (7.3), this is SF99725, which is shown in the screen shot below.

We now have Java installed on our server and can start using it.

The first step to take is to set an environment variable to tell Java which version we want to use.

The command below, shows the settings required to use the 64-bit version.

ADDENVVAR ENVVAR(JAVA_HOME) VALUE(‘/QOpenSys/QIBM/ProdData/JavaVM/jdk80/64bit’) LEVEL(*JOB)

To use the 32-bit version, the environment variable would be as follows.

ADDENVVAR ENVVAR(JAVA_HOME) VALUE(‘/QOpenSys/QIBM/ProdData/JavaVM/jdk80/32bit’) LEVEL(*JOB)

IBM recommends you do not set the JAVA_HOME environment variable to be the *SYSTEM level, as this may negatively affect applications already setting their own versions to run in.

If you wish to specify the version in a shell session, for your job, we can use the export JAVA_HOME variable to use whichever version you require.

The example below shows me using the 64-bit version..

export JAVA_HOME=/QOpenSys/QIBM/ProdData/JavaVM/jdk80/64bit

This will set the JAVA_HOME variable to affect only jobs using this shell session.  If you wish this to always apply to a users session, it is advised you use a shell session profile for the user.

To check which version of Java you are using, use a shell session and run.

JAVA -VERSION

The screen shot of my server shows we are running the 64-bit version.

What Java versions are your jobs running?

To check which version of Java your jobs are running, use the Work with JVM Job command (WRKJVMJOB).

From this screen, take an option 5 to display the JVM job you need to know about.

The screen shot below shows our schools REST service using the 64-bit version of the JDK toolkit.

Java Programs

In this section we will write a very simple Java program and run it.

First thing to note about Java programs, is that they are compiled.  Java is not an interpreted language like many other languages, PHP, Node.JS etc.

Let me copy a Hello World example into our IFS.

Back into our shell, we can see our source and compile it.

  1. Our java source file
  2. Compile our source using the JAVAC command
  3. We now have the compiled object called Hello.class
  4. We call our Java compiled program (be aware of case!)
  5. Shows the output from our java program

Support

You will be pleased to know that the Java Development Kit is included in your Software Maintenance Agreement (SWMA) with IBM if you are on Version 7.3 or Version 7.4 of the OS.

If you are hitting any problems, open a PMR.

Conclusion

Hopefully, this article has given you a quick insight into the Java world on the IBM i. 

I will be giving a one-day workshop on everything Node.js and Open Source at the next i-UG user group meeting in July 2021 in the UK.  Hopefully, we can all meet up again and get back to normal, government restrictions permitting.

If you have any questions, either on this article, or anything else open source, use the comments below, or send me a message on twitter @AndyYouens

Andy Youens is an IBM i consultant/instructor at Milton Keynes, UK-based FormaServe Systems with over 40 years IBM midrange experience. 

IBM Champion 2021

How useful was this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.


Comments

One response to “A Java on IBM i Intro”

  1. Hello Andy,

    Your “A Java on IBM i Intro” article was helpful in understanding how to use QSHELL to compile java programs on IBM i.

    I am having a bit of a problem that I hope you might be able to help me with.
    I am trying to use JavaMail on IBM i from an RPGLE program to send emails to smtp.gmail.com
    I have been looking for examples to help me understand how to deal with the Authentication part (SSL/TLS), but have had no luck in finding an RPGLE example. The examples I am finding are all pure Java. Using an old version of RPGMAIL (Aaron Bartell), I have been able to send an email from an RPGLE program to multiple recipients with multiple attachments – but that version does not use gmail or authentication.
    A further complication is that it appears that the Javax extension package was deprecated in 2020 and replaced by Jakarta,
    All of the examples I have seen so far use Javax and not Jakarta, which indicates to me that they were all written before 2020.
    I have seen IBM documentation that “All the JavaMail components are shipped as part of SS1 (product ID 5770-SS1) Option 3”, which we have installed. But that documentation says nothing about Javax or Jakarta. So I don’t know if the IBM implementation will support sending emails with authentication to smtp.gmail.com. IBM support has not been very helpful in this matter and have been steering us towards using the IBM i as a forwarding mail server and using the Google Admin Console and Workspace (which we do not have).
    I would greatly appreciate any help or guidance on this that you might be able to pass on regarding this,
    Mike McManus

Leave a Reply

Your email address will not be published. Required fields are marked *