Blog from September, 2009

Whenever you create web services there is the problem where to store the service contracts. What you need is some kind of service repository. Of course there are good products that support this. But typically they are quite expensive and quite complex. So why not use the maven repository for this task?  It already does a great job storing jars of libraries and zips of complete applications.

So what does a service repository based on a maven repository offer?

  • Great integration into your build process (if you use maven for your builds)
  • Support for namespaces (groupIds)
  • Support for versioning
  • Support for fast roundtripps with SNAPSHOT versions of your service contracts (WSDLs)
  • The pom of an application using services documents which services in which version are used
  • Support independent organizations or business units by using separate maven repositories

How is a service contract mapped to the maven repository?

So how is a service contract stored in the maven repository? Just like any other library. For example you would store the service
service name: PizzaService
version: 1.0.0
as the following maven artifact


This artifact is represented in the maven repo by the file:


How can the service contract be created and uploaded?

The howto Defining Contract first webservices with wsdl generation from java shows how to easily create a wsdl from a service definition in Java. From CXF 2.3.0 on you can easily deploy the generated wsdl file to the maven repo. Simply add the following to the configuration section of the java2ws plugin:


The basic usage of the java2ws plugin is described in the CXF User Guide - Maven Integration.

If you create the wsdl file in another way or do not use CXF 2.3.0 you can use the build helper maven plugin with the goal attachArtifact.

Retrieving the service contract and generating source code from it

So you have the wsdl in the maven repo. How do you retrieve it and build the java stubs from it?

Before CXF 2.3.0 you could use the copy-dependency goal of the maven dependencies plugin. This copies a maven artifact from the maven repo to the target directory. Then you would use the cxf codegen plugin to generate the java code.

From CXF 2.3.0 on the codegen plugin can retrieve the wsdl directly from the maven repo.