Managing Java AS/400 errors for 'xxxx class not found'

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'
 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 . . . . . . . . . :   

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:

  1. Cut the source code below as text into a file with the java extension:
  2. 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.
  3. Start QShell.
  4. Change to the IFS directory with the java file (eg. cd /myJava).
  5. Compile the java source file into a class (eg. javac
  6. 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 = 				20
	user.language = 				en
	java.home = 				/QIBM/ProdData/Java400/jdk117
	os400.class.path.rawt = 				0
	awt.toolkit =
	os400.class.path.system = 				PRE
	file.encoding.pkg =
	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 = 				program_create_type
	os400.debug = 				0 = 				CCBS
	os.arch = 				PowerPC
	os400.optimization = 				10 = 				OS/400 = 				0
	os400.defineClass.optLevel = 				20
	java.vendor.url =
	user.dir = 				/tmp/java
	java.class.path = 			
	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 last published in September 2000

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.