0

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'

ZioN
  • 550
  • 2
  • 11
  • 35

1 Answers1

2

You have to remove the package name from the classpath:

:/home/WAL60326/TutorialProject

should do it.

John Smith
  • 2,282
  • 1
  • 14
  • 22
  • 1
    without changing the `.class` files location of course. class files must allways reside in a directory structure that equals their package structure: `my.cool.package.JavaCallClass` must reside in `my/cool/package`. This is by the way how `.jar` files are structured internally (they are simple `.zip` files with a different filename extension). – John Smith Aug 22 '13 at 06:53
  • You might have to check file system permissions if changing the CLASSPATH does not solve the problem. – John Smith Aug 22 '13 at 06:56