JAX WS with maven2

jaxws wsdl helloworld

I have to fiddle around with webservices during my work, we use JAX WS for generating the glue code. I wanted to create a HelloWorld example (again), only to realize that everything is already online (again).

I want to combine maven and JAX-WS. I’ve found the web page for Jax WS here, and more importantly, an example pom which contains everything you need for jaxws here.

One problem of the average Bob D. Veloper is that information about a specific problem may be available, but instead of solving your specific problem it raises again more questions. For example, the referenced pom above uses the antrun plugin to download a wsdl, which is no problem at all – if you look at the code and uncomment the lines where the wsdl is retrieved from the web. In order to make it work you should consider to remove the comment in the antrun configuration section.

Another problem is that you should know how to invoke maven properly in order to generate your artifacts. As always, it is easier as I thought initially, a simple

mvn package

or

mvn compile

first downloads the wsdl and secondly creates your webservice clients in the target directory.

As you surely know, it is best practice to generate the glue code from the wsdl; by placing the classes in the target directory, you are typically not tempted to change them (for whatever reason). As always, modify the source, not the artifacts. DRY you know.

Anyway, with a few commands you’ll get a ready to go implementation for an arbitrary webservice, both client and server implementation is generated. The only thing you now have to do is to fill out parameters and hope for the best.

There are many websites which provide an api for their services – if a wsdl is available, you are ready to go.

Another acronym popping up “recently” (first draft 2005 ;)   is WADL. Oh man.

Leave a Reply