2010-02-19 70 views
2

我使用axis2-1.5中的wsdl2java生成了.java文件。现在它生成了以下文件夹结构中的文件:src/net/mycompany/www/services/如何使用WSDL2Java生成的文件?

services文件夹中的文件是:SessionIntegrationStub和SessionIntegrationCallbackHandler。

我想现在使用webservice。我将网络文件夹添加到CLASSPATH环境变量。我的Java文件现在进口使用WebService:

import net.mycompany.www.services; 

public class test 
{ 
    public static void main(String[] args) 
    { 
    SessionIntegrationStub stub = new SessionIntegrationStub(); 
    System.out.println(stub.getSessionIntegration("test")); 
    } 
} 

现在,当我尝试使用这个编译:

的javac test.java

我得到:包net.mycompany.www不存在。

有什么想法?

回答

0

这应该可以说是import net.mycompany.www.services.*;。你错过了星号。

+0

我试过了。但是现在它找不到生成的存根。我的标题看起来像这样:package net.mycompany.www.services;导入net.mycompany.services。*,其中当前文件位于services文件夹中。 – vikasde 2010-02-19 20:54:49

2

正如已经建议需要导入生成的存根类,而不是它的包

import net.mycompany.www.services.SessionIntegrationStub; 

然后,您需要填写您的XML请求对象。我不知道您的WSDL是什么样子,但例如

SessionIntegrationStub.SessionRequest req = new SessionIntegrationStub.SessionRequest() 
req.setParamOne(1) 
req.setParamTwo(2) 

最后调用Web服务

SessionIntegrationStub.SessionResponse resp = stub.operationOne(req) 

println resp.getAnswer() 

注意:上述对应于你的模式中声明元素的getter和setter方法。 SessionRequest和SessionResponse类将对应于您的模式中声明的复杂类型。

0

问题在这里是你的包装结构。你的test.java是在不同的包中,然后是你生成的源文件。

你需要保持当前文件在同一封装结构或提供的javac的产生源的完整路径类似

的javac的src/NET/myCompany中/网络/服务/ 的.java的src/NET/myCompany中/服务/ .java