JAX-WS Service and Client On Single Eclipse Project

There are many excellent tutorials on creating and consuming Java JAX-WS Web Services. Yet it seems that every JAX-WS tutorial instructs you to create a Dynamic Web Project for the service and then another project for the client. This post shows you how to work with both your JAX-WS service and client on a single Eclipse Dynamic Web Project.

To get a look at what we’re after, here’s the Project Explorer with both the Web Services and Client in the same Eclipse project. In our Java Resources both our service and client are shown, and in WebContent we see our wsdl and client .JSPs which we’ll see in action later.

Creating a Client Namespace in Eclipse

To house both web service and client on the same we need to map our service package to a namespace our client can use which is different from the web service package.

When we create the Web Service (not client) in Eclipse we have the option of mapping the web service package to a different namespace for the client to use.

Our web service package is com.nixmash.janglesweb.wservice, so we’re going to map that to com.nixmash.janglesweb.wsclient. Notice the reverse hierarchy order of the namespace.

Here is our WSDL with the mapped namespace our Web Services Client will use.

Creating the Web Services Client

We don’t need to do any additional mapping at this point, simply create the Web Services Client as we normally do.

Our Web Service Client files are generated in their own package as you can see.

We’ll import that package when calling the service.

Here’s the proof of happy co-existence of web service and client.