Deploying Java 6 Web Services in Tomcat
- Published April 18th, 2007 in Java
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 version="1.0" encoding="UTF-8"?>
-
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/j2ee/dtds/web-app_2_3.dtd">
-
<web -app>
-
<listener>
-
</listener><listener -class>
-
com.sun.xml.ws.transport.http.servlet.WSServletContextListener
-
</listener>
-
-
<servlet>
-
</servlet><servlet -name>HelloService</servlet>
-
<servlet -class>
-
com.sun.xml.ws.transport.http.servlet.WSServlet
-
</servlet>
-
<load -on-startup>1</load>
-
-
<servlet -mapping>
-
</servlet><servlet -name>HelloService</servlet>
-
<url -pattern>/hello</url>
-
-
<session -config>
-
</session><session -timeout>60</session>
-
-
</web>
The sun-jaxws.xml looks like this:
-
<?xml version="1.0" encoding="UTF-8"?>
-
<endpoints xmlns="http://java.sun.com/xml/ns/jax-ws/ri/runtime" version="2.0">
-
<endpoint name="HelloService"
-
implementation="com.techyatra.hellows.HelloServer"
-
url-pattern="/hello"
-
/>
-
</endpoints>
After starting tomcat you can access the service under
-
http://localhost:8080/HelloService/hello
Done!
References
This quite hard to find brief tutorial was taken from here. Due credits to Tobias Dittrich




Simple Elegant
Thanks
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