Calling methods in your own classes

When you use your own Java™ classes, the class that you specify in the EXTPROC and CLASS keywords is simply the name of the class. If the class is part of a package, you include the package information in the keywords. For example, consider the following two classes:


 class Simple                                  
 {                                             
    static void method (void)                  
    {                                          
       System.out.println ("Simple method");   
    }                                          
 }                                             

 package MyPkg;                                
                                               
 class PkgClass                                
 {                                             
    static void method (void)                  
    {                                          
       System.out.println ("PkgClass method"); 
    }                                          
 }                                             

If the Simple class file is /home/myclasses/Simple.class, you would specify the directory /home/myclasses in your CLASSPATH environment variable, and you would specify 'Simple' as the class name in your RPG keywords.

If the PkgClass class file is /home/mypackages/MyPkg/PkgClass.class, you would specify the directory /home/mypackages (the directory containing the package) in your CLASSPATH environment variable, and you would specify 'MyPkg.PkgClass' (the package-qualified Java class) as the class name in your RPG keywords.

The class name for your RPG keywords is the same name as you would specify in your import statements in your Java classes. You use the CLASSPATH environment variable to specify the location of the class files, or the location of the directory containing the package.
Note: Note: If you have classes in a jar file, you specify the jar file itself in your classpath.
===> ADDENVVAR CLASSPATH '/home/myclasses:/home/mypackages:/home/myjarfiles/j1.jar'
Figure 1. Creating an RPG prototype for a Java method in a package

 D simpleMethod    PR                  EXTPROC(*JAVA          
 D                                           : 'Simple'       
 D                                           : 'method')      
 D                                     STATIC                 
 D pkgMethod       PR                  EXTPROC(*JAVA          
 D                                           : 'Pkg.PkgClass' 
 D                                           : 'method')      
 D                                     STATIC