JAX-WS Web Service Deployment on Tomcat Server With Examples

We learned how to use JAX-WS to create SOAP web services and publish it using javax.xml.ws.Endpoint but most of the times we want to deploy our services on a servlet container. So today we will learn how to create a web service and deploy it on Apache Tomcat server and then test it out with the client application.

For this, our first step is to create a Dynamic Web Project to write our business logic. Our final project will look like below image.


For JAX-WS web service deployment on a servlet container, we need to add some jar files into it. There are two ways to do this.

  1. Download jar files from https://jax-ws.java.net/ and include it in the dynamic web project.
  2. Convert Dynamic web project into Maven and add below dependencies.

    This will automatically download all the required jar files as maven dependencies shown in the below image. I like this approach because I can upgrade the versions easily and it will also make sure none of the jars are getting missed.


  3. JAXWS-Tomcat-Project-421x450

Now let’s go through the business logic. First, we will create a model bean class.

Now we will create our service interface and implementation classes.

Our web service code is ready, next steps are required to create it as a web archive that we can deploy in the servlet container.

There is nothing project-specific, these are generic changes to add listener class and front servlet class for web service.

Next step is to create sun-jaxws.xml file inside WEB-INF directory where we will provide endpoint details. URL-pattern should be same as defined in the web.xml file.


That’s it, we are done. Just export project as a WAR file and deploy it into tomcat container. Access the web service URL as shown in below image.


Access the WSDL URL and take note of targetNamespace and name attributes, we will use them in the client side program.


Below is a simple test program to use our web service and run some tests.

As explained in previous tutorial, we can use wsimport utility to generate client stubs and use it. When we run above program, we get output as shown in below image.


That’s all for now, I hope you liked the tutorial and it will help you in deploying web services in Tomcat container.

By admin

Leave a Reply

%d bloggers like this: