website stat

Deploying Java 6 Web Services in Tomcat

I've told before how easy it is to develop JAX WS with Java 6 and how one might use JDK6 builtin light-weight web server to test it out. Unfortunately, the light-weight suffers severe performance problems so any concurrent access will simply neck it out. It's fine for development though.

So the alternative is using a real Web Server like Tomcat, Geronimo, Axis, Jetty, etc.. Since the production server I'm using runs Tomcat I decided to stick with it.

The worst part was definitely figuring out how to do it. It took me quite a while to find an insightful post detailing what to do. Since these forums don't last long nowadays I'll rewrite the tutorial myself here.

First, you must use Tomcat 6 since we're using JDK6. Then, you'll need JAX WS. You should download version 2.0

Briefly, here are the steps required:

  • Download and unpack the jax-ws (java -jar jax-ws.jar)
  • Copy all *.jar from the lib dir into $CATALINA_HOME/lib
  • Create a directory for the service under $CATALINA_HOME/webapps
  • Copy the class structure from the web service into WEB-INF/classes in that directory (if you have any jar files on your classpath then also create a folder WEB-INF/lib and throw them there)
  • Create a sun-jaxws.xml in WEB-INF
  • Create web.xml in WEB-INF
  • Start tomcat. Done

The web.xml should look something like this:

XML:
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/j2ee/dtds/web-app_2_3.dtd">
  3. <web -app>
  4. <listener>
  5. </listener><listener -class>
  6. com.sun.xml.ws.transport.http.servlet.WSServletContextListener
  7. </listener>
  8.  
  9. <servlet>
  10. </servlet><servlet -name>HelloService</servlet>
  11. <servlet -class>
  12. com.sun.xml.ws.transport.http.servlet.WSServlet
  13. </servlet>
  14. <load -on-startup>1</load>
  15.  
  16. <servlet -mapping>
  17. </servlet><servlet -name>HelloService</servlet>
  18. <url -pattern>/hello</url>
  19.  
  20. <session -config>
  21. </session><session -timeout>60</session>
  22.  
  23. </web>

The sun-jaxws.xml looks like this:

XML:
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <endpoints xmlns="http://java.sun.com/xml/ns/jax-ws/ri/runtime" version="2.0">
  3. <endpoint name="HelloService"
  4. implementation="com.techyatra.hellows.HelloServer"
  5. url-pattern="/hello"
  6. />
  7. </endpoints>

After starting tomcat you can access the service under

HTML:
  1. http://localhost:8080/HelloService/hello

Done!

References

This quite hard to find brief tutorial was taken from here. Due credits to Tobias Dittrich


2 Responses to “Deploying Java 6 Web Services in Tomcat”

  1. Prakash S
    Published at April 27th, 2007 at 9:29 am

    Simple Elegant
    Thanks

  2. xin
    Published at May 2nd, 2007 at 12:19 pm

    1 unbenannt [text/plain] 0,33 KB

    Hello Mario,

    I have readed your article “Deploying Java 6 Web Services in Tomcat”. Could you write the
    whole process very detail and completly again? (inclusive Webservce.java,servlet.java,
    and how can i deploy it)I have tried it 3 weeks and no result. Please help me!!

    Thank you very much
    Xin