生成WSDL时出现Axis2错误

3
我正在尝试使用 JAX-WS 和 JAXB 注解开发一个新的 Web 服务。 当我在 axis2 中部署 .jar 并打开浏览器检索生成的 .wsdl 文件时,我收到了以下错误提示:
[ERROR] Error occurred generating WSDL file for Web service implementation class {foo.bar.myServiceImpl}
java.lang.NoClassDefFoundError: com/sun/xml/ws/api/server/Container
        at java.lang.Class.getDeclaredMethods0(Native Method)
        at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
        at java.lang.Class.getMethod0(Unknown Source)
        at java.lang.Class.getMethod(Unknown Source)
        at org.apache.axis2.jaxws.description.builder.JAXWSRIWSDLGenerator.generateWsdl(JAXWSRIWSDLGenerator.java:179)
        at org.apache.axis2.jaxws.description.builder.JAXWSRIWSDLGenerator.initialize(JAXWSRIWSDLGenerator.java:390)
        at org.apache.axis2.jaxws.description.builder.JAXWSRIWSDLGenerator.getWSDL(JAXWSRIWSDLGenerator.java:383)
        at org.apache.axis2.description.AxisService.printWSDL(AxisService.java:1394)
        at org.apache.axis2.transport.http.HTTPWorker.service(HTTPWorker.java:154)
        at org.apache.axis2.transport.http.server.AxisHttpService.doService(AxisHttpService.java:281)
        at org.apache.axis2.transport.http.server.AxisHttpService.handleRequest(AxisHttpService.java:187)
        at org.apache.axis2.transport.http.server.HttpServiceProcessor.run(HttpServiceProcessor.java:82)
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: com.sun.xml.ws.api.server.Container
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        ... 15 more

挖掘源码后,我注意到com.sun.xml.ws.api.server.Container是jaxws-rt实现的一部分,而它并不属于Axis2发行版(在/lib/文件夹中找不到)。为什么会这样?我有所遗漏吗?
2个回答

2

好的,我明白了。 我会发布答案,以避免其他人撞墙。

我在系统上设置了一个旧的JAVA_HOME环境变量。它指向安装程序的JRE,但需要指向已安装的JDK。就是这样。


你能否将这个标记为被接受的答案,这样它就不会继续显示为未回答的问题了吗? - Kenster
我很想这样做,但是根据stackoverflow的提示,我需要再等待21个小时。 - Bjarne77
@Bjarne77 我也遇到了同样的错误,但我不知道如何解决这个问题,因为在我的Java Home中我已经安装了Java 13 JDK。 - valik
不确定@valik,我认为主要的解决方案是在运行/构建时仔细检查是否使用了SDK实现。这已经太久远了,不能提供有价值的信息。抱歉。 - Bjarne77

2

我有同样的问题。我需要向jaxws-maven-plugin添加依赖项。如果没有这些依赖项,它会抛出相同的错误。

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>jaxws-maven-plugin</artifactId>
            <configuration>
                <wsdlDirectory>src/main/resources/wsdl/</wsdlDirectory>
                <keep>true</keep>
                <sourceDestDir>${project.build.directory}/generated-sources/wsimport</sourceDestDir>
                <sei></sei>
            </configuration>
            <dependencies>
                <dependency>
                    <groupId>com.sun.xml.ws</groupId>
                    <artifactId>jaxws-rt</artifactId>
                    <version>2.1.4</version>
                </dependency>
                <dependency>
                    <groupId>com.sun.xml.ws</groupId>
                    <artifactId>jaxws-tools</artifactId> 
                    <version>2.1.4</version>
                </dependency>
            </dependencies>
            <executions>
                <execution>
                    <id>generate-from-wsdl</id>
                    <goals>
                        <goal>wsimport</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接