尝试使用 hello word webservice 时出错:ClassNotFoundException: org.apache.axis2.databinding.ADBException

Error when trying to use a hello word webservice : ClassNotFoundException: org.apache.axis2.databinding.ADBException

我在 2-3 天后出现错误,所以我有一个 axis2 项目,我正在尝试在服务器端使用以下网络服务:

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>

但是当我尝试从客户端使用 hello world 服务时,我遇到了以下错误

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 服务器无法识别注释

感谢您的帮助。

//编辑:2020 年 5 月 5 日 我正在使用 maven,axis2 罐子已经添加到模块中:

一些依赖项是使用提供的范围定义的,不会在运行时自动添加。

解决方案是更改 pom.xmlchange the Run/Debug configuration to include the dependencies with the provided scope in runtime 中的依赖项范围。