Generate jax-ws server and client with maven

For running this example follow these requirements:

  • Jdk: 6 or later
  • Tomcat: ~7

Generate web service implementation

First off, create a maven project with ArchetypeArtifactId = maven-archetype-webapp

Once your maven web project is created, edit pom.xml and add the following lines:

Now let’s create your web service implementation.

Create a class HelloProvider.java and write as follow:

Edit web.xml and add servlet information:

In the same folder WEB-INF add a file called sun-jaxws.xml and put this:

Your web service is ready to be built and deployed.

Run maven clean install and deploy the generated .war file from target folder into tomcat server.

Trying this address

http://localhost:8080/TestWebService/helloProvider?wsdl

should display the wsdl structure.

Generate Web Service Client

Create a simple default project

Edit pom.xml and add the following lines:

Then run maven clean install to generate the client files into target/generated-sources folder.

Please notice:

In order to import wsdl from local file instead of remote url, edit pom.xml in this way:

To access local files, following lines are required

 

Next create JaxWsClient.java file and put this code:

Running this code should write “Hello Fabrizio Starred” on the output.

Leave a Reply

Your email address will not be published. Required fields are marked *