I am trying to minimize required configuration while deploying JAX-WS-based Web service on Tomcat. With the introduction of Servlet 3.0 (supported by Tomcat 7+), web.xml
can be thrown out, but there is still sun-jaxws.xml
. This blog post is interesting:
Of course, with the use of jax-ws annotations, even configuration sun-jaxws.xml can be made optional making it completely descriptor free, but that requires specifying a default url-pattern like in JSR-109 or custom pattern like in Jersey REST services, in the JAX-WS specification.
Is it possible to avoid sun-jaxws.xml
on Tomcat, and how?
Sadly, the configuration must exist somewhere. That is mandatory, per the source. Believe it or not, the location of the sun-jaxws.xml file is hard-coded to /WEB-INF/sun-jaxws.xml (thanks, guys @ Metro).
Effectively, you need to take control of the following classes
What needs to happen:
WSServletContextListener
will obviously not be extended. This listener performs most of the initializations per the sun-jaxws.xml and jaxws-catalog file. Like I mentioned earlier, the location is hard coded. So your path of least resistance here is to
implement your own vanilla servlet listener (with @WebListener
) and call a new WSServletContextListener()
. You'll then delegate your own contextInitialized(ServletContext ctxt)
and contextDestroyed()
methods to the ones in your instance of WSServletContextListener
.
Generate the file on instantiation of the listener, on the fly, using an @XmlRootElement
class that'll represent the sun-jaxws file(I'll provide a sample of this in a short while, don't have the time right now :) ).
It's a lot of trouble for such a dispensable convenience, IMO, but it should work in theory. I'll write some samples and see how they play shortly.