java 使用 Metro 2.1 的 Tomcat 7.0.11 上的 WSServlet ClassNotFoundException 错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6041770/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 14:06:02  来源:igfitidea点击:

WSServlet ClassNotFoundException error on Tomcat 7.0.11 using Metro 2.1

javaweb-servicesjax-wsjava-metro-frameworktomcat7

提问by user758752

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:

我正在尝试使用 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

in the catalina.properties file I have:

在 catalina.properties 文件中,我有:

server.loader=c:/metro-2.1/bin/*.jar 

(note, I also tried adding this path to common.loader too).

(注意,我也尝试将此路径添加到 common.loader 中)。

I've copied to the following METRO jar files to CALALINA_HOME\lib:

我已将以下 METRO jar 文件复制到 CALALINA_HOME\lib:

webservices-api.jar, webservices-extra.jar, webservices-extra-api.jar, webservices-rt.jar, webservices-tools.jar

webservices-api.jar、webservices-extra.jar、webservices-extra-api.jar、webservices-rt.jar、webservices-tools.jar

and to CALALINA_HOME\endorsed:

和 CALALINA_HOME\endorsed:

webservices-api.jar

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.*)

(注意,我最初尝试使用 Metro-on-tomcat.xml ant 文件,但它似乎没有针对 tomcat 7 进行更新。*)

I've also copied webservices-api.jar to JAVA_HOME\jre\lib\endorsed

我还将 webservices-api.jar 复制到 JAVA_HOME\jre\lib\endorsed

I've tried putting the other METRO jars in the above locations aswell too but to no help.

我也试过将其他 METRO 罐子也放在上述位置,但没有帮助。

Now, Tomcat starts up ok and initializes METRO ok, here's the relevant section from the catalina log file:

现在,Tomcat 启动正常并初始化 METRO ok,这是 catalina 日志文件中的相关部分:

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

信息:部署 Web 应用程序目录 ROOT 18-May-2011 08:00:55 com.sun.xml.ws.transport.http.servlet.WSServletContextListener contextInitialized INFO:WSSERVLET12:JAX-WS 上下文侦听器初始化 18-May-2011 08: 01:07 com.sun.xml.ws.server.MonitorBase createRoot INFO:Metro 监控根名称成功设置为: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 初始化

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:

因此,您会认为 Tomcat 已经加载了所有 METRO 类。从我收集到的信息来看,WSServlet 是 JAX-WS 2.1 的一部分,它是作为 METRO 的一部分提供的,所以它应该已经被加载了。但是当我真正尝试浏览到我的服务的 WSDL 时,我在 localhost 日志中得到以下信息:

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)

严重:在 org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1676) 处为 servlet TempConvertWS java.lang.ClassNotFoundException 分配异常:com.sun.xml.ws.transport.http.WSServlet。 catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1521) 在 org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:415)....(堆栈跟踪的其余部分)

my sun-jaxws.xml looks like this:

我的 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>

and the relevant section from my web.xml file is:

我的 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>

Can anyone see from that why Tomcat can't find/load the WSServlet class when browsing to the service?

谁能从中看出为什么 Tomcat 在浏览服务时找不到/加载 WSServlet 类?

回答by Paaske

With Tomcat 6, I set shared.loader in catalina.properties and added webservices-api.jar to <catalina-home>\endorsed

使用 Tomcat 6,我在 catalina.properties 中设置了共享.loader 并将 webservices-api.jar 添加到<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>/libinsteadof using the shared.loader directive. I find that this is also more compatible with Eclipse.

出于开发和测试目的,您可以将 webservices-extra.jar、webservices-extra-api.jar、webservices-rt.jar、webservices-tools.jar 放入<catalina-home>/lib而不是使用 shared.loader 指令。我发现这也与 Eclipse 更兼容。

I will test with Tomcat 7 to see if it differs in any way.

我将使用 Tomcat 7 进行测试,看看它是否有任何不同。

*Update: Same trick works for Tomcat 7.0.14

*更新:同样的技巧适用于 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 be com.sun.xml.ws.transport.http.servlet.WSServlet

*更新2:很抱歉我没有立即看到它,但我刚刚注意到在您的 web.xml 中,指定<servlet-class>的错误。它应该是com.sun.xml.ws.transport.http.servlet.WSServlet