我正在尝试使用 tomcat 发布一个简单的 java web 服务。参考下面的屏幕截图,我有HelloWorld.java,它是服务接口及其HelloWorldImpl.java实现类。
我还创建了web.xml和sun-jaxws.xml。
当我右键单击项目时,选择Run As然后Run on Server,我收到 404 错误消息,如屏幕截图底部所示。
内部浏览器尝试访问的 URL是项目名称的http://localhost:8081/MySqlConnect/
位置。MySqlConnect
请注意,我使用8081
的是端口号。
我也试过http://localhost:8081/HelloWorld/hello
,但没有奏效。
我还提供了以下所有文件的代码。
我无法理解我哪里出错了?任何帮助表示赞赏。
HelloWorldImpl.java
package com.mycompany.service;
import javax.jws.WebService;
@WebService(endpointInterface = "com.mycompany.service.HelloWorld", serviceName = "HelloWorld")
public class HelloWorldImpl implements HelloWorld {
@Override
public String sayGreeting(String name) {
return "Greeting " + name + "!";
}
}
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems,
Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/j2ee/dtds/web-app_2_3.dtd">
<web-app>
<listener>
<listener-class>
com.sun.xml.ws.transport.http.servlet.WSServletContextListener
</listener-class>
</listener>
<servlet>
<servlet-name>hello</servlet-name>
<servlet-class>
com.sun.xml.ws.transport.http.servlet.WSServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>hello</servlet-name>
<url-pattern>/hello</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>120</session-timeout>
</session-config>
</web-app>
太阳jaxws.xml
<?xml version="1.0" encoding="UTF-8"?>
<endpoints xmlns="http://java.sun.com/xml/ns/jax-ws/ri/runtime"
version="2.0">
<endpoint name="HelloWorld" implementation="com.mycompany.service.HelloWorldImpl"
url-pattern="/hello" />
</endpoints>
编辑 1
日志猫
INFO: Starting Servlet Engine: Apache Tomcat/7.0.33
com.sun.xml.ws.transport.http.servlet.WSServletContextListener parseAdaptersAndCreateDelegate
SEVERE: WSSERVLET11: failed to parse runtime descriptor: java.lang.NoClassDefFoundError: javax/xml/ws/soap/AddressingFeature$Responses
java.lang.NoClassDefFoundError: javax/xml/ws/soap/AddressingFeature$Responses
Caused by: java.lang.ClassNotFoundException: javax.xml.ws.soap.AddressingFeature$Responses
编辑 2
正如这里所建议的,我下载了所有库并将其放入 tomcat lib 文件夹中,但现在我在日志中收到此错误:
com.sun.xml.ws.transport.http.servlet.WSServletContextListener parseAdaptersAndCreateDelegate
SEVERE: WSSERVLET11: failed to parse runtime descriptor: java.lang.NoSuchMethodError: com.sun.xml.ws.assembler.TubelineAssemblyController: method <init>()V not found
java.lang.NoSuchMethodError: com.sun.xml.ws.assembler.TubelineAssemblyController: method <init>()V not found
如果我将所有库添加到项目然后尝试运行它,我会收到以下错误:
com.sun.xml.ws.transport.http.servlet.WSServletContextListener parseAdaptersAndCreateDelegate
SEVERE: WSSERVLET11: failed to parse runtime descriptor: com.sun.xml.ws.util.ServiceConfigurationError: com.sun.xml.ws.policy.jaxws.spi.PolicyFeatureConfigurator: Provider com.sun.xml.ws.transport.tcp.policy.TCPTransportFeatureConfigurator is specified in jar:file:/C:/Apache-Tomcat-7/lib/webservices-rt-2.1-b16.jar!/META-INF/services/com.sun.xml.ws.policy.jaxws.spi.PolicyFeatureConfiguratorbut could not be instantiated: java.lang.ClassCastException
com.sun.xml.ws.util.ServiceConfigurationError: com.sun.xml.ws.policy.jaxws.spi.PolicyFeatureConfigurator: Provider com.sun.xml.ws.transport.tcp.policy.TCPTransportFeatureConfigurator is specified in jar:file:/C:/Apache-Tomcat-7/lib/webservices-rt-2.1-b16.jar!/META-INF/services/com.sun.xml.ws.policy.jaxws.spi.PolicyFeatureConfiguratorbut could not be instantiated: java.lang.ClassCastException
请注意:com.sun.xml.ws.policy.jaxws.spi.PolicyFeatureConfigurator 但无法实例化:java.lang.ClassCastException