简体   繁体   English

RPG调用Java,java.lang.NoClassDefFoundError

[英]RPG calling Java, java.lang.NoClassDefFoundError

My aim is to call a Web Service from Java, initiated from a RPG function. 我的目标是从RPG函数启动的Java调用Web服务。 (I know, its long way around, but it is what we need) (我知道,很长的路要走,但这是我们需要的)

I have created a /JavaLib folder on the AS400, and copied all our needed External Jars we need. 我在AS400上创建了一个/JavaLib文件夹,并复制了我们需要的所有所需的外部Jar。

Create a Java class with a static method WebServiceCaller.Call() to call a Web Service. 使用静态方法WebServiceCaller.Call()创建Java类以调用Web服务。 When ever I run my RPG program everything is fine unto the RPG calls this method. 每当我运行RPG程序时,RPG都将此方法称为一切正常。

I get a Java exception: 我收到一个Java异常:

Message . 信息 。 . . . : Java exception received when calling Java method (CGDF). :调用Java方法(CGDF)时收到Java异常。
Cause . 原因。 . . . . : RPG procedure WEBSERCALR in program WAL60326/WEBSERCALR received Java exception "java.lang.NoClassDefFoundError: :程序WAL60326 / WEBSERCALR中的RPG过程WEBSERCALR收到Java异常“ java.lang.NoClassDefFoundError:
javax.xml.rpc.ServiceException" when calling method "Call" with signature "(LwebService.Input;)LwebService.Output;" in class 在类中调用带有签名“(LwebService.Input;)LwebService.Output;”的方法“ Call”时,javax.xml.rpc.ServiceException”
"webService.WebServiceCaller". “ webService.WebServiceCaller”。

CLASSPATH variable: CLASSPATH变量:

/JavaLib:/home/WAL60326/WebServiceCaller / JavaLib:/ home / WAL60326 / WebServiceCaller

So I believe my RPG and Java Class is fine, and I believe I have setup my CLASSPATH variable right. 因此,我相信我的RPG和Java类很好,而且我相信我已经正确设置了CLASSPATH变量。 Not sure what else there is to check. 不知道还有什么要检查。


Update 更新资料

So the jar file I need is jaxrpc.jar I have checked; 所以我需要的jar文件是我检查过的jaxrpc.jar it does exists in my /JavaLib . 它确实存在于我的/JavaLib Was able to check my Java version on the AS400 java version "1.5.0" . 能够在AS400 java version "1.5.0"上检查我的Java版本。 And follow these instructions to check that my OS is V6R1. 并按照以下说明检查我的操作系统是否为V6R1。

Could it be my Java version that is out of date, for this Jar file to be loaded/work? 要加载/工作这个Jar文件,可能是我的Java版本过时了吗? Is that even a possibility? 那有可能吗?


Edit 编辑

Here is my source code: 这是我的源代码:

Java: WebServiceCaller.Java 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;
    }
}

Take note that the GetBidsProxy class in generated by Eclipse. 请注意,Eclipse生成了GetBidsProxy类。 And the Java side works well on my Windows Machine. Java端在我的Windows机器上运行良好。 Just not on the AS400 Machine. 只是不在AS400机器上。

RPG: WEBSERCALR.RPGLE 角色扮演游戏:WEBSERCALR.RPGLE

 H DFTACTGRP(*NO)
 H thread(*serialize)

 D WebsercalInput  DS
 D   ReturnCode                   7A
 D   LogKey                      20A
 D   ID                          20A

 D jString         S               O   CLASS(*JAVA:'java.lang.String')
 D jLogKey         S               O   CLASS(*JAVA:'java.lang.String')
 D jID             S               O   CLASS(*JAVA:'java.lang.String')
 D Input           S               O   CLASS(*JAVA:'webService.Input')
 D Output          S               O   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

The CLASSPATH is read only once for a given job, the first time you invoke the java command and the JVM starts. 对于给定的作业,第一次调用java命令并且JVM启动时,CLASSPATH只读一次。 If your CLASSPATH changes after that, the JVM won't see or use the new CLASSPATH. 如果之后更改了CLASSPATH,则JVM将不会看到或使用新的CLASSPATH。 Sign off and on (to start a new job), set the CLASSPATH (I do it in my signon program) and then try to use the class you're working with. 先注销然后再登录(以开始新工作),设置CLASSPATH(我在登录程序中完成此操作),然后尝试使用正在使用的类。

If the CLASSPATH is correct then the other thing to check is the Java prototype in your RPG program. 如果CLASSPATH正确,则要检查的另一件事是RPG程序中的Java原型。 It needs to exactly match the Java class definition. 它需要与Java类定义完全匹配。

First, make 100% certain that your jaxrpc.jar has all the classes you think it should. 首先,100%确保jaxrpc.jar具有您认为应该的所有类。 Start QShell, then java tf /JavaLib/jaxrpc.jar . 启动java tf /JavaLib/jaxrpc.jar ,然后启动java tf /JavaLib/jaxrpc.jar Make sure you have at least these: 确保您至少具有以下这些:

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

Next, do a simple proof of concept program in pure Java to make sure all of the pieces work as you expect them to. 接下来,使用纯Java做一个简单的概念验证程序,以确保所有部分都能按预期工作。 Note: JAX-RPC is obsolete and goes away in Java 1.6 and up. 注意:JAX-RPC已过时,并且在Java 1.6及更高版本中已不再使用。 It's been replaced by JAX-WS. 它已被JAX-WS取代。 If this is a brand new app, consider using the more current implementation. 如果这是一个全新的应用程序,请考虑使用最新的实现。 This 2006 DeveloperWorks article explains some of the differences. 2006年的developerWorks文章解释了其中的一些区别。

Once you have a pure Java program written, it's time to take the Java classes that you used and prototype them in RPG. 一旦编写了一个纯Java程序,就该使用您使用的Java类并在RPG中对其进行原型设计了。 Assuming you've done all of that, could you edit your question to show the RPG *CLASS prototypes and the RPG code used to invoke them. 假设您已完成所有操作,是否可以编辑问题以显示RPG * CLASS原型以及用于调用它们的RPG代码。 Basically, see if someone reading this question can re-create the set-up on a different box. 基本上,看看是否有人阅读此问题可以在其他盒子上重新创建设置。

I've used some Java in my RPG code and I found out that it's not enough to add the container folder to the CLASSPATH. 我在RPG代码中使用了一些Java,但发现仅将容器文件夹添加到CLASSPATH中还不够。 I had to identify the individual jars in the CLASSPATH. 我必须在CLASSPATH中标识各个jar。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM