使用 Metro 2.1 的 Tomcat 7.0.11 上出现 WSServlet ClassNotFoundException 错误
我正在尝试使用 Metro 2.1 在 Windows Server 2008 R2 上使用 Tomcat 7.0.11 创建一个简单的 Web 服务。我有 C#/WCF 背景,试图更好地了解 Web 服务互操作性。我实际上正在遵循 Martin Kalin 的书“Java Web Services Up and Running”中的示例。我有以下内容:
CATALINA_HOME=c:\tomcat-7.0.11
在 catalina.properties 文件中我有:(
server.loader=c:/metro-2.1/bin/*.jar
注意,我也尝试将此路径添加到 common.loader 中)。
我已将以下 METRO jar 文件复制到 CALALINA_HOME\lib:
webservices-api.jar, webservices-extra.jar, webservices-extra-api.jar, webservices-rt.jar, webservices-tools.jar
并到 CALALINA_HOME\endorsed:
webservices-api.jar
(注意,我最初尝试使用metro-on-tomcat.xml ant文件,但它似乎没有针对tomcat 7进行更新。*)
我还将webservices-api.jar复制到JAVA_HOME \jre\lib\endorsed
我也尝试将其他 METRO jar 放在上述位置,但没有帮助。
现在,Tomcat 启动正常并初始化 METRO 正常,以下是 catalina 日志文件中的相关部分:
信息:部署 Web 应用程序 目录根 2011 年 5 月 18 日 08:00:55 com.sun.xml.ws.transport.http.servlet.WSServletContextListener 上下文初始化信息:WSSERVLET12: JAX-WS 上下文侦听器初始化 2011 年 5 月 18 日 08:01:07 com.sun.xml.ws.server.MonitorBase createRoot INFO:地铁监控 rootname 成功设置为: com.sun.metro:pp=/,类型=WSEndpoint,名称=-TempConvertImplService-TempConvertImplPort 2011 年 5 月 18 日 08:01:08 com.sun.xml.ws.transport.http.servlet.WSServletDelegate 信息:WSSERVLET14:JAX-WS servlet 初始化
因此,您会认为 Tomcat 已经加载了所有 METRO 类。据我所知,WSServlet 是 JAX-WS 2.1 的一部分,JAX-WS 2.1 作为 METRO 的一部分提供,因此应该已加载。但是,当我实际尝试浏览服务的 WSDL 时,我在本地主机日志中收到以下内容:
严重:为 servlet 分配异常 临时转换WS java.lang.ClassNotFoundException: com.sun.xml.ws.transport.http.WSServlet 在 org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1676) 在 org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1521) 在 org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:415).... (堆栈跟踪的其余部分)
我的 sun-jaxws.xml 看起来像这样:
<endpoints xmlns="http://java.sun.com/xml/ns/jax-ws/ri/runtime" version="2.0">
<endpoint
name="TempConvertWS"
implementation="TimeServer.TempConvertImpl"
url-pattern="/tc"
/>
</endpoints>
我的 web.xml 文件中的相关部分是:
<listener>
<listener-class>com.sun.xml.ws.transport.http.servlet.WSServletContextListener</listener-class>
</listener>
<servlet>
<servlet-name>TempConvertWS</servlet-name>
<servlet-class>com.sun.xml.ws.transport.http.WSServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>TempConvertWS</servlet-name>
<url-pattern>/tc</url-pattern>
</servlet-mapping>
任何人都可以从中看出为什么 Tomcat 在浏览服务时无法找到/加载 WSServlet 类吗?
I'm trying to create a simple webservice using Tomcat 7.0.11 on Windows Server 2008 R2 using Metro 2.1. I'm coming from a C#/WCF background trying to get a better understanding on web service interopability. I'm actually following an example from Martin Kalin's book "Java Web Services Up and Running". I have the following:
CATALINA_HOME=c:\tomcat-7.0.11
in the catalina.properties file I have:
server.loader=c:/metro-2.1/bin/*.jar
(note, I also tried adding this path to common.loader too).
I've copied to the following METRO jar files to CALALINA_HOME\lib:
webservices-api.jar,
webservices-extra.jar,
webservices-extra-api.jar,
webservices-rt.jar,
webservices-tools.jar
and to CALALINA_HOME\endorsed:
webservices-api.jar
(note, I originally tried using the metro-on-tomcat.xml ant file but it doesn't seem to have been updated for tomcat 7.*)
I've also copied webservices-api.jar to JAVA_HOME\jre\lib\endorsed
I've tried putting the other METRO jars in the above locations aswell too but to no help.
Now, Tomcat starts up ok and initializes METRO ok, here's the relevant section from the catalina log file:
INFO: Deploying web application
directory ROOT 18-May-2011 08:00:55
com.sun.xml.ws.transport.http.servlet.WSServletContextListener
contextInitialized INFO: WSSERVLET12:
JAX-WS context listener initializing
18-May-2011 08:01:07
com.sun.xml.ws.server.MonitorBase
createRoot INFO: Metro monitoring
rootname successfully set to:
com.sun.metro:pp=/,type=WSEndpoint,name=-TempConvertImplService-TempConvertImplPort
18-May-2011 08:01:08
com.sun.xml.ws.transport.http.servlet.WSServletDelegate
INFO: WSSERVLET14: JAX-WS
servlet initializing
So from that you'd think that Tomcat had loaded all the METRO classes. From what I have gathered WSServlet is part of JAX-WS 2.1 which is shipped as part of METRO so it should have been loaded. But when I actually try to browse to the WSDL of my service I get the following in the localhost log:
SEVERE: Allocate exception for servlet
TempConvertWS
java.lang.ClassNotFoundException:
com.sun.xml.ws.transport.http.WSServlet
at
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1676)
at
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1521)
at
org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:415)....
(rest of stack trace)
my sun-jaxws.xml looks like this:
<endpoints xmlns="http://java.sun.com/xml/ns/jax-ws/ri/runtime" version="2.0">
<endpoint
name="TempConvertWS"
implementation="TimeServer.TempConvertImpl"
url-pattern="/tc"
/>
</endpoints>
and the relevant section from my web.xml file is:
<listener>
<listener-class>com.sun.xml.ws.transport.http.servlet.WSServletContextListener</listener-class>
</listener>
<servlet>
<servlet-name>TempConvertWS</servlet-name>
<servlet-class>com.sun.xml.ws.transport.http.WSServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>TempConvertWS</servlet-name>
<url-pattern>/tc</url-pattern>
</servlet-mapping>
Can anyone see from that why Tomcat can't find/load the WSServlet class when browsing to the service?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 Tomcat 6 中,我在 catalina.properties 中设置了 shared.loader,并将 webservices-api.jar 添加到\endorsed
这非常有效。
出于开发和测试目的,您可以将 webservices-extra.jar、webservices-extra-api.jar、webservices-rt.jar、webservices-tools.jar 放入
/lib
而不是使用shared.loader指令。我发现这也与 Eclipse 更兼容。我将使用 Tomcat 7 进行测试,看看它是否有任何不同。
*更新:同样的技巧适用于 Tomcat 7.0.14
*更新2:很抱歉我没有立即看到它,但我刚刚注意到在您的 web.xml 中,指定的< /代码> 是错误的。它应该是 com.sun.xml.ws.transport.http.servlet.WSServlet
With Tomcat 6, I set shared.loader in catalina.properties and added webservices-api.jar to
<catalina-home>\endorsed
That worked like a charm.
For development and testing purposes you could just put the webservices-extra.jar, webservices-extra-api.jar, webservices-rt.jar, webservices-tools.jar into
<catalina-home>/lib
instead of using the shared.loader directive. I find that this is also more compatible with Eclipse.I will test with Tomcat 7 to see if it differs in any way.
*Update: Same trick works for Tomcat 7.0.14
*Update2: I'm sorry I didn't see it at once, but I just noticed that in your web.xml, the specified
<servlet-class>
is wrong. It should becom.sun.xml.ws.transport.http.servlet.WSServlet