问题
I have a JAX-WS web service application which deploys as a WAR file for Tomcat 7. It uses a recent version of the Metro libraries, which I include inside the WAR file, and it works fine.
I'm trying to simplify the deployment package. I understand that the Sun JDK includes a copy of Metro (see this question and this one for example), yet for some reason, it's apparently mandatory to replace this copy of metro with one downloaded from the glassfish site. I'm trying to understand if it's possible to get by with just Tomcat and the metro implementation that comes with the JDK, or if not why not.
The WAR contents are as follows (class files removed):
META-INF/MANIFEST.MF
WEB-INF/classes/
WEB-INF/classes/com/[et cetera]
WEB-INF/ibm-web-ext.xml
WEB-INF/lib/
WEB-INF/lib/stax-api.jar
WEB-INF/lib/webservices-api.jar
WEB-INF/lib/webservices-extra-api.jar
WEB-INF/lib/webservices-extra.jar
WEB-INF/lib/webservices-rt.jar
WEB-INF/lib/webservices-tools.jar
WEB-INF/sun-jaxws.xml
WEB-INF/web.xml
wsdl/
wsdl/MyService.wsdl
web.xml
contains, in part:
<servlet>
<servlet-name>MyService</servlet-name>
<servlet-class>
com.sun.xml.ws.transport.http.servlet.WSServlet
</servlet-class>
</servlet>
When I remove the webservices-* jars--the Metro jars--from the WAR, the web service fails with the error " Wrapper cannot find servlet class com.sun.xml.ws.transport.http.servlet.WSServlet or a class it depends on". This isn't surprising because I can't find that class anywhere in the jars that come with Java 7 SE.
So, what does it mean to say that Java 7 comes with Metro, if you have to download another copy of Metro to make something like this work? Is it possible to run a JAX-WS web service within Tomcat using just the jars that come with Java?
回答1:
Bundled JAX-WS lacks integration with servlet containers, as it is intended to be used only to offer JAX-WS services inside standalone Java applications (WTF!?!?!?).
Of course, one could think of implementing a servlet that does that integration, so you would not have to include another copy of Metro in your WAR. But it is easier to just include an external "full" copy, it bloats the WAR but should not have a great performance penalty. Furthermore, in this way you can control which version you use, avoiding to get stuck with the version that was included in your JRE.
Anyway, Sun usually changed package names in bundled libraries so they would not collide with external ones, Therefore, if the servlet would exist (it does not), it would probably be called:
com.sun.xml. internal. ws.transport.http.servlet.WSServlet
This is very annoying as they also changed some configuration properties in the same way (e.g.: timeout related ones), so if you use the bundled JAX-WS you have to use
com.sun.xml. internal.... style configuration properties,
but if you use some external JAX-WS you have to use
com.sun.xml.... style configuration properties.
Thanks Sun!!
回答2:
So, what does it mean to say that Java 7 comes with Metro..?
This is not entirely correct. JDK6+ includes JAX-WS RI (reference implementation), and Metro is a superset of it. In other words, Metro = JAX-WS RI + WSIT.
Is it possible to run a JAX-WS web service within Tomcat using just the jars that come with Java?
This is an excellent question. Answer is - no, because WSServlet
class extends HttpServlet
, and WSServletContextListener
implements ServletContextAttributeListener
and ServletContextListener
interfaces. These interfaces and classes are all part of Java EE, not Java SE - thus not included in JDK/JRE. Sun/Oracle decided not to mix Java SE and Java EE, and that's understandable even though it means that these classes have been actually taken out of JAX-WS RI version that comes with JDK/JRE. Therefore, you have to install JAX-WS dependencies in order to use JAX-WS-based Web services on Tomcat, because Tomcat doesn't come with it (on the other hand, if you choose Glassfish for example, you will find complete Metro distribution bundled with it and you don't have to install anything additionally). Otherwise, you are stuck with Endpoint#publish mechanism.
See also:
- WSServletContextListener and WSServlet in JRE 6
回答3:
Its a old question but if someone is still looking for answers. Its not necessary to include the jaxws jar as of JDK 1.7 (I'm using precisely 1.7.0_45). Used this http://www.mkyong.com/webservices/jax-ws/deploy-jax-ws-web-services-on-tomcat/ link to build a sample webservice and have skipped the step 5 and it all works. I'm targeting Tomcat version 7.0.47, entire project is build with Maven with default scope for jaxws-rt jars (i.e. compile).
来源:https://stackoverflow.com/questions/15798351/jax-ws-implementation-included-with-java