O'Reilly logo

Java SOA Cookbook by Eben Hewitt

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Generating a WSDL and Portable Artifacts Based on a Java Service Endpoint Implementation

Problem

You want to generate a WSDL and portable web service artifacts (classes based on the WSDL) starting from a service implementation class.

Solution

Use the wsgen command-line tool, included with JAX-WS.

Discussion

Create a Java class annotated with @WebService, and then execute the wsgen tool that comes with Java. It will generate the following portable artifacts for you:

  • A WSDL file, if you indicate so using the -wsdl option. The wsgen tool will only generate a WSDL if you explicitly specify this option.

  • JAXB classes required to marshal and unmarshal the messages exchanged in the service definition.

There is only one argument required by wsgen: the name of the Java class that implements your web service. You can also specify a variety of options. The form of using the tool is:

$ wsgen [options] service-implementation-class

Table 7-1 illustrates the set of options available for wsgen.

Table 7-1. Options for the wsgen tool

OptionPurpose
-classpath <path> or -cp <path>Specifies where to find input class files.
-d <directory>Specifies where to place generated output files. This directory must exist before running wsgen.
-extensionSpecifies whether to allow vendor extensions.
-helpShows the usage.
-keepSpecifies whether to retain generated files.
-r <directory>Specifies Destination directory for resource files such as WSDLs. Can only be used when the -wsdl option is also used.
-s <directory>Specify where to ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required