尝试使用hello-word Web服务时出错:ClassNotFoundException:org.apache.ax



从现在起2-3天内我就出现了一个错误,所以我有一个axis2项目,我正在尝试在服务器端使用以下Web服务:

HelloService.java

public class HelloService {
public String sayHelloWorldFrom(String from) {
String result = "Hello, world, from " + from;
System.out.println(result);
return result;
}
}

这是我生成的wsdl

<?xml version="1.0" encoding="UTF-8"?><wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:ns="http://hello.org" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ns1="http://org.apache.axis2/xsd" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" targetNamespace="http://hello.org">
<wsdl:documentation>HelloService</wsdl:documentation>
<wsdl:types>
<xs:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://hello.org">
<xs:element name="sayHelloWorldFrom">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="from" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="sayHelloWorldFromResponse">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="return" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
</wsdl:types>
<wsdl:message name="sayHelloWorldFromRequest">
<wsdl:part name="parameters" element="ns:sayHelloWorldFrom"/>
</wsdl:message>
<wsdl:message name="sayHelloWorldFromResponse">
<wsdl:part name="parameters" element="ns:sayHelloWorldFromResponse"/>
</wsdl:message>
<wsdl:portType name="HelloServicePortType">
<wsdl:operation name="sayHelloWorldFrom">
<wsdl:input message="ns:sayHelloWorldFromRequest" wsaw:Action="urn:sayHelloWorldFrom"/>
<wsdl:output message="ns:sayHelloWorldFromResponse" wsaw:Action="urn:sayHelloWorldFromResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="HelloServiceSoap11Binding" type="ns:HelloServicePortType">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<wsdl:operation name="sayHelloWorldFrom">
<soap:operation soapAction="urn:sayHelloWorldFrom" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="HelloServiceSoap12Binding" type="ns:HelloServicePortType">
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<wsdl:operation name="sayHelloWorldFrom">
<soap12:operation soapAction="urn:sayHelloWorldFrom" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="HelloServiceHttpBinding" type="ns:HelloServicePortType">
<http:binding verb="POST"/>
<wsdl:operation name="sayHelloWorldFrom">
<http:operation location="sayHelloWorldFrom"/>
<wsdl:input>
<mime:content type="application/xml" part="parameters"/>
</wsdl:input>
<wsdl:output>
<mime:content type="application/xml" part="parameters"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="HelloService">
<wsdl:port name="HelloServiceHttpSoap11Endpoint" binding="ns:HelloServiceSoap11Binding">
<soap:address location="http://localhost:8080/Server_war_exploded/services/HelloService.HelloServiceHttpSoap11Endpoint/"/>
</wsdl:port>
<wsdl:port name="HelloServiceHttpSoap12Endpoint" binding="ns:HelloServiceSoap12Binding">
<soap12:address location="http://localhost:8080/Server_war_exploded/services/HelloService.HelloServiceHttpSoap12Endpoint/"/>
</wsdl:port>
<wsdl:port name="HelloServiceHttpEndpoint" binding="ns:HelloServiceHttpBinding">
<http:address location="http://localhost:8080/Server_war_exploded/services/HelloService.HelloServiceHttpEndpoint/"/>
</wsdl:port>
</wsdl:service>

但是,当我尝试从客户端使用helloworld服务时,我会出现以下错误

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/axis2/databinding/ADBException
at org.hello.HelloService.main(HelloService.java:10)
Caused by: java.lang.ClassNotFoundException: org.apache.axis2.databinding.ADBException
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
... 1 more
Process finished with exit code 1

因此,正如您在HelloService.java中看到的,我不使用jaw-xs注释,因为Tomcat服务器不识别注释

谢谢你的帮助。

//编辑:05/05/2020我使用的是maven,axis2 jar已经添加到模块中:

  • 服务器
  • 客户

一些依赖项是用Provided作用域定义的,它在运行时不会自动添加。

解决方案是更改pom.xml中依赖项的范围,或者更改运行/调试配置以在运行时包含具有所提供范围的依赖项。

最新更新