Question

Trying to call a Java Method from RPG, I have been following the manuals Introduction to Java and RPG and Calling Java Methods from ILE RPG.

But when I call my RPG function that calls my java function I get the following error:

Java exception received when calling Java method (C G D F).

Pressing F1 reveals the following message:

Message . . . . : Java exception received when calling Java method (C G D F).
Cause . . . . . : RPG procedure HELLO in program DEVLYNLIB/HELLO received Java exception "java.lang.NoClassDefFoundError: JavaCallClass (wrong name: test/JavaCallClass)" when calling method "test.CallStaticMethod" with
signature "(II)I" in class "JavaCallClass".

Here is my Java Class:

package test;

public class JavaCallClass {
    public static int CallStaticMethod(int number1, int number2) {
    return number1 + number2;
}

RPG Function:

 H thread(*serialize)

 D StaticMethod    PR            10I 0 EXTPROC(*JAVA:
 D                                       'test.JavaCallClass':
 D                                       'CallStaticMethod')
 D                                     STATIC
 D  number1                      10I 0 VALUE
 D  number2                      10I 0 VALUE

 D sum             S             10I 0

  /free
   sum = StaticMethod(5:10);
   return;
  /end-free 

I think it may have to do something with my CLASSPATH variable, I believe I have set it right. My Java class file is at /home/WAL60326/TutorialProject/test

Here is my full CLASSPATH variable value:

'/Plex/Objava/lib/obrun.jar:/Plex/WsydXml11.jar:/PLEX/JT400.JAR:/PLEX/WSYDUTIL.JAR:/Plex/xercesImpl.jar:/Plex/xalan.jar:/PLEX/XML-APIS.JAR:/PLEX/WSYDDWA21.JAR:/PLEX/COMMONS-HTTPCLIENT-3.1.JAR:/PLEX/COMMONS-LOGGING-1.1.JAR:/PLEX/COMMONS-CODEC-1.3.JAR:/PLEX/ADDRESSBOOK.JAR:/PLEX/NEXTNUM.JAR:/PLEX/UDC.JAR:/PLEX/P6SERVICES.JAR:/PLEX/MASTERVOCAB.JAR:/home/WAL60326/TutorialProject/test'

Was it helpful?

Solution

You have to remove the package name from the classpath:

:/home/WAL60326/TutorialProject

should do it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top