Developers, Developers, Developers! Maksim Sorokin IT Blog


JAX-WS web services + Maven + Tomcat

There is an awesome article about Deploy JAX-WS web services on Tomcat. It describes how to have a web service running without much effort.
We will follow the article and do the same, but with three differences:

  • We will build it with Maven
  • We will omit interface in the web service
  • We will not copy jars to the Tomcat. All dependencies will be managed by Maven

Let's start by creating a fresh maven project jaxwsExample. pom.xml will contain single JAX-WS dependency (which will be automatically downloaded from Maven Central) and will look as following:

<project xmlns="" xmlns:xsi=""


  <name>JAX-WS Example</name>


The project was war type, so there fore it has to look as described in War plugin page.

We create a package inside src/main/java with the name and create class HelloWs with web service annotations as in mkyong's article, but without interface. We just put all annotations inside the class itself:


import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;

@SOAPBinding(style = Style.RPC)
public class HelloWs {

  public String sayHello(String name) {
    if (name == null) {
      return "Hello";

    return "Hello, " + name + "!";

Then we create sun-jaxws.xml file and put it to src/main/webapp/WEB-INF folder:

<?xml version="1.0" encoding="UTF-8"?>
<endpoints xmlns="" version="2.0">
  <endpoint name="HelloWs" implementation="" url-pattern="/HelloWs" />

After it, we create web.xml in the same directory src/main/webapp/WEB-INF folder, again following original article:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="" xmlns=""
  xmlns:web="" xsi:schemaLocation=""
  id="WebApp_ID" version="2.5">



And that is it. We do not need to define compilation manually, as it is done by maven. We also do not need to drop JAX-WS dependencies to Tomcat lib folder as they are managed by maven.

Now we just build the project with maven by mvn clean install, rename it to jaxwsExample.war (we can do that automatically in maven, but omit it for simplicity) and deploy it to the Tomcat.

Now we can access the web service on http://localhost:8080/jaxwsExample/HelloWs.

If you take a look inside the war file, you will notice that it added other dependencies automatically.

You can download the sources of jaxwsExample

Comments (1) Trackbacks (1)
  1. Thanks! You saved my life!

Leave a comment