iSeries Java exception java.lang.NoClassDefFoundError - AS400 Message ID RNX0301

There could be various reasons why you are getting this error. I am going to to explain here what are the various things that you can check to resolve this issue. Before I dig into the issues here is a sample java program that I am going to use for explanation.

Sample Java Code

package com.as400samplecode; 

public class SimpleJava { 

 public static void main(String[] args) { 

  String firstName = args[0].trim(); 
  String lastName = args[1].trim(); 
  String age = args[2].trim(); 

  System.out.println("First Name: " + firstName); 
  System.out.println("Last Name: " + lastName); 
  System.out.println("Age: " + age); 



1) Check you current directory

When calling the Java program you must be in the same directory where the class resides.

From command Line or CL program use
CD DIR('/directory1/directory2/...') 

From Qshell
CD '/directory1/directory2/...' 

D Exc_Cmd         PR                  extpgm('QCMDEXC')    
D  command                     200A   const                
D  length                       15P 5 const                

     Exc_Cmd('CD (''/directory1/directory2/...'')': 200);     

2) Check Spelling

Java is case sensitive ! Can't call SimpleJava as Simplejava

3) Check Package

When you compile the program which has package definition as below

package com.as400samplecode;

It will create the class file in the path

Don't make your current directory to that mentioned above ! You must call as shown below ...

From Command Line or CL Program
RUNJVA CLASS(com.as400samplecode.SimpleJava) PARM('Albert' 'Who' '35')

From Qshell
java com.as400samplecode.SimpleJava "Albert" "Who" "35"

From RPGLE (Click here for complete Code)
 * Prototype for SimpleJava Main() function                            
d SimpleMain      PR                  EXTPROC(*JAVA:                   
d                                     'com.as400samplecode.Simplejava':
d                                     'main')                          
d                                     STATIC                           
d String                          O   CLASS(*JAVA:'java.lang.String')  
d                                     dim(3)                           
d                                     Const 

No comments:

Post a Comment

NO JUNK, Please try to keep this clean and related to the topic at hand.
Comments are for users to ask questions, collaborate or improve on existing.