RPG calling Java, java.lang.NoClassDefFoundError

My goal is to invoke a Java web service initiated with an RPG function. (I know its a long way, but that is what we need)

I created the /JavaLib folder on the AS400 and copied all the external Jars we need.

Create a Java class with the static method WebServiceCaller.Call() to call the web service. When I run my RPG program, everything is fine when the RPG calls this method.

I get a Java exception:

Message. ,,: Java exception received when calling the Java method (CGD F).
Reason. ,,: RPG procedure WEBSERCALR in program WAL60326 / WEBSERCALR received Java exception "java.lang.NoClassDefFoundError:
javax.xml.rpc.ServiceException "when calling the Call method with the signature" (LwebService.Input;) LwebService.Output; "in the class
"WebService.WebServiceCaller".

CLASSPATH variable:

/ JavaLib: / Home / WAL60326 / WebServiceCaller

So, I believe that my RPG and Java class are fine, and I believe that I have correctly set my CLASSPATH variable. Not sure what else to check.


Update

So I need a jar file jaxrpc.jar ; it exists in my /JavaLib . Could check my version of Java on AS400 java version "1.5.0" . And follow these instructions to verify that my OS is V6R1.

Maybe my version of Java is deprecated since this Jar file is loading / working? Is this even an opportunity?


Edit

Here is my source code:

Java: WebServiceCaller.Java

 package webService; import java.rmi.RemoteException; import stocklistGetBids.GetBidsProxy; public class WebServiceCaller { public static Output Call(Input in) { // Input Class, is just a way to hold all the input together Output out = null; // Output Class, holds all the output together try { GetBidsProxy getBidsProxy = new GetBidsProxy(); // GetBidsProxy generated by Eclipse out = new Output(getBidsProxy.getBids(in.LogKey, in.Id)); } catch (RemoteException e) { e.printStackTrace(); out = new Output("ERR"); } return out; } } 

Note that the GetBidsProxy class is created in Eclipse. And the Java side works well on my Windows machine. Just not on an AS400.

RPG: WEBSERCALR.RPGLE

  H DFTACTGRP(*NO) H thread(*serialize) D WebsercalInput DS D ReturnCode 7A D LogKey 20A D ID 20A D jString SO CLASS(*JAVA:'java.lang.String') D jLogKey SO CLASS(*JAVA:'java.lang.String') D jID SO CLASS(*JAVA:'java.lang.String') D Input SO CLASS(*JAVA:'webService.Input') D Output SO CLASS(*JAVA:'webService.Output') D new_Input PR O EXTPROC(*JAVA: D 'webService.Input': D *CONSTRUCTOR) D LogKey like(jString) D ID like(jString) D new_String PR O EXTPROC(*JAVA: D 'java.lang.String': D *CONSTRUCTOR) D bytes 30A CONST VARYING D Call PR like(Output) D EXTPROC(*JAVA: D 'webService.WebServiceCaller': D 'Call') D STATIC D in like(Input) D getReturnStat PR O EXTPROC(*JAVA: D 'webService.Output': D 'getReturnedStatus') D CLASS(*JAVA:'java.lang.String') D getBytes PR 65535A VARYING D EXTPROC(*JAVA: D 'java.lang.String': D 'getBytes') C *ENTRY PLIST C PARM WebsercalInput /free jLogKey = new_String(LogKey); jID = new_String(ID); Input = new_Input(jLogKey:jID); Output = Call(Input); jString = getReturnStat(Output); ReturnCode = getBytes(jString); return; /End-Free 
+4
source share
3 answers

CLASSPATH is read only once for a given job, the first time you run the java command and the JVM starts. If your CLASSPATH changes after this, the JVM will not see or use the new CLASSPATH. Turn it off and on (to start a new task), install CLASSPATH (I do this in my signon program), and then try to use the class you are working with.

+3
source

If CLASSPATH is correct, then the other thing to check is the Java prototype in your RPG program. It must exactly match the definition of the Java class.

First, make 100% certain that your jaxrpc.jar has all the classes you think should be. Run QShell, then java tf /JavaLib/jaxrpc.jar . Make sure you have at least:

 javax/xml/rpc/Call.class javax/xml/rpc/ServiceFactory.class javax/xml/rpc/ServiceException.class 

Then do a simple proof of concept of the program in pure Java, to make sure that all parts work as you expect. Note. JAX-RPC is deprecated and goes to Java 1.6 and above. It has been replaced by JAX-WS. If this is a brand new application, consider using a more current implementation. This DeveloperWorks article explains some of the differences.

After you write a clean, written Java program, it's time to take the Java classes you used and prototype them in an RPG. Assuming you did all this, could you please change your question to show the prototypes of RPG * CLASS and the RPG code used to call them. Basically, see if anyone reading this question can recreate the setting in another field.

+1
source

I used some Java in my RPG code and I found out that this is not enough to add a container folder to CLASSPATH. I had to identify individual banks in CLASSPATH.

0
source

Source: https://habr.com/ru/post/1498554/


All Articles