尝试使用问候语webservice时出错:ClassNotFoundException:org.apache.axis2.databinding.ADBException

问题描述 投票:1回答:1

从现在开始的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>

但是当我尝试从客户端使用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中看到,因为Tomcat服务器无法识别注释,所以我不使用jaw-xs注释

感谢您的帮助。

// Edit:05/05/2020我正在使用Maven,并且axis2 jar已添加到模块中:

xml tomcat intellij-idea axis2
1个回答
0
投票

某些依赖项是通过Provided范围定义的,它不会在运行时自动添加。

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

© www.soinside.com 2019 - 2024. All rights reserved.