Managing your AS/400 Java Classpath correctly is one of the biggest problems programmers new to Java have. You go to try a Java sample application, and it doesn't work with the message: ' xxx class not found'. Similar in concept to an AS/400 library list, the classpath is the search path you define for Java to find classes. Part of the classpath covers the IBM directories in IFS that contain IBM Java directories, zip files and jars. On the AS/400, this is automatically added to the classpath. Other classes you want to access either need to be in the current directory you start the application from OR found on the classpath that exists at runtime. You specify IFS directories, zip files and jar files that you want Java to search for classes when it runs an application.
On the AS/400 you set the classpath using the WRKENVVAR CL command. There are two modes to set: *JOB or *SYS. By default the command sets the classpath for the JOB option only. When your jobs ends, the classpath definition is gone. To set the systemwide classpath (*SYS), you need to have AS/400 administrator authority. If you plan to set the system classpath, be sure you are not impacting other installed Java applications on your AS/400. Below is the WRKENNVAR command where you add an environment variable for CLASSPATH (all uppercase) as I have.
//==================================================================\
Display Device . . . . . : QPADEV0001
User . . . . . . . . . . : CCBS
Work with Environment Vars (*JOB)
Type options, press Enter.
1=Add 2=Change 4=Remove 5=Display details 6=Print
Opt Name Value
__ CLASSPATH '.:/tmp:/veeryServlet:/as400user:/a'
QIBM_MULTI_THREADED 'Y'
NOTES_AS400_STSDEBUG '1'
Bottom
Parameters or command
===>
F3=Exit F4=Prompt F5=Refresh F9=Retrieve F11=Display
F12=Cancel F16=Print list F17=Top F18=Bottom F22=Display
\==================================================================//
Below I've displayed the current classpath I set:
//==================================================================\
Display Device . . . . . : QPADEV0001
User . . . . . . . . . . : CCBS
Display Environment Var (*JOB)
Name . . . . . . . . . : CLASSPATH
Value . . . . . . . . . :
'.:/tmp:/veeryServlet:/as400user:/as400java:/veeryS
ervlet/claim.jar:/javaToolkit/jt400.jar:/as400java/ivjsb30.jar:/as400jav
a/ivjdab.jar:/webSphere/jsdk.jar:/as400java/swing.jar'
\==================================================================//
You can also programmatically view the FULL classpath that is in effect using a simple Java tool I wrote that lists the current Java system properties, including the classpath. To create my simple Java tool, do the following:
- Cut the source code below as text into a file with the java extension: ShowSystemProperties.java.
- Store this in an IFS directory. I use FTP, but you can also map a Windows drive to the AS/400 IFS directories if NetServer is running and you have authority to copy files.
- Start QShell.
- Change to the IFS directory with the java file (eg. cd /myJava).
- Compile the java source file into a class (eg. javac ShowSystemProperties.java).
- Run the application (e.g. java ShowSystemProperties). By default output is sent to the system console in QShell so you can view it online.
The output listing is below, and the source code follows that:
Current system properties list ... ShowSystemProperties os400.create.type = direct os400.class.path.security.check = 20 user.language = en java.home = /QIBM/ProdData/Java400/jdk117 os400.class.path.rawt = 0 awt.toolkit = com.ibm.rawt.client.CToolkit os400.class.path.system = PRE file.encoding.pkg = sun.io java.version = 1.1.7 file.separator = / line.separator = os400.stdin.allowed = 1 os400.class.path.system.setdefault = PRE user.region = US file.encoding = ISO8859_1 os400.interpret = 0 java.vendor = IBM Corporation user.timezone = UTC os400.verify.checks.disable = 65535 os400.run.mode = program_create_type os400.debug = 0 user.name = CCBS os.arch = PowerPC os400.optimization = 10 os.name = OS/400 os400.class.path.tools = 0 os400.defineClass.optLevel = 20 java.vendor.url = http://www.ibm.com user.dir = /tmp/java java.class.path = /QIBM/ProdData/Java400/jdk117/lib/jdkptf117.zip:/QIBM/ProdData/Jav a400/jdk117/lib/classes.zip:/QIBM/ProdData/Java400/ext/IBMmisc.jar:/QIBM /ProdData/Java400/ext/db2_classes.jar:/QIBM/ProdData/Java400/ext/jssl.ja r:/QIBM/ProdData/Java400/ext/ibmjssl.jar:/QIBM/ProdData/Java400/:.:/tmp: /veeryServlet:/as400user:/as400java:/veeryServlet/claim.jar:/javaToolkit /jt400.jar:/as400java/ivjsb30.jar:/as400java/ivjdab.jar:/webSphere/jsdk. jar:/as400java/swing.jar java.class.version = 45.3 os.version = V4R4M0 path.separator = : user.home = /home/CCBS/
Jim Mason is president of Cape Cod Bay Systems, an IBM and Lotus business partner focused on delivering e-business application solutions for AS/400 customers. Jim also writes, consults, teaches, designs and develops AS/400 Web applications using Java, WebSphere, DB2, Lotus Domino and the WebSphere Development Tools for AS/400.
This was first published in September 2000