Thursday, September 26, 2013

Deploy JAX-WS web service in Tomcat Server

if the web service is going to be deployed in the tomcat server,it has to be developed as a web application project with some added configurations.
in order to start the web application project, i prefer to use maven archetype generate command as follows.

mvn archetype:generate -DarchetypeArtifactId=maven-archetype-webapp

then it will give me a basic web application project that can be built with maven.
now this is the time to integrate my predefined web service with the web application project.

1. first create the relevant package structure in the web-app project and copy the web service src files there.

2. create the web service deployment descriptor ( sun-jaxws.xml ) file under the webapp/WEB-INF directory. (same directory where the web.xml resides).
 the endpoints should be defined as follows.

<?xml version="1.0" encoding="UTF-8"?>



3. in web.xml file (standard deployment descriptor) defines the WSServletContextListener and WSServlet class as follows.


 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"

 "" >

  <display-name>Archetype Created Web Application</display-name>





3.  if you do all the above steps correctly, you project structure should be as follows.

now it is the time to build the web service. since the web service is published in the tomcat server, it should be built as a WAR file similar to simple web app.

4.  once the web service is compiled and package, copy the WAR file to the webapps directory in the tomcat server.

5. sometimes the web service not be loaded because the tomcat does not have the required libraries to server for web services (By default, Tomcat does not comes with any JAX-WS dependencies). In that case you need to download those dependencies and copy to the “${Tomcat}/lib” directory.

  •  Go here
  • Download JAX-WS RI distribution.
  • Unzip it and copy following JAX-WS dependencies to Tomcat library folder “{$TOMCAT}/lib“.
    • jaxb-impl.jar
    • jaxws-api.jar
    • jaxws-rt.jar
    • gmbal-api-only.jar
    • management-api.jar
    • stax-ex.jar
    • streambuffer.jar
    • policy.jar

once the above depdencies are copied, restart the tomcat server and try to access the web serice with following URL.


if the web service is working, it should display the following page in the browser.
then we are done.


the all steps taken for publishing a web service in tomcat can be summarized as below.
  1. Create a web service
  2. Create a sun-jaxws.xml, defines web service implementation class.
  3. Create a standard web.xml, defines WSServletContextListener, WSServlet and structure of a web project
  4. Copy JAX-WS dependencies to “${Tomcat}/lib” directory.
  5. Generate WAR file and copy to “${Tomcat}/webapp” directory.
  6. access the web service from browser and check whether it is up and running.


Hope this might be helpful for you!

Chathuranga Tennakoon

No comments:

Post a Comment