Generating the Starting Point Code
JAX-WS specifies a detailed mapping from a service defined in WSDL to the Java classes that will implement that service. The logical interface, defined by the wsdl:portType element, is mapped to a service endpoint interface (SEI). Any complex types defined in the WSDL are mapped into Java classes following the mapping defined by the Java Architecture for XML Binding (JAXB) specification. The endpoint defined by the wsdl:service element is also generated into a Java class that is used by consumers to access endpoints implementing the service.
The wsdl2java command automates the generation of this code. It also provides options for generating starting point code for your implementation and an ant based makefile to build the application. wsdl2java provides a number of arguments for controlling the generated code.
Running wsdl2java
You can generate the code needed to develop your service using the following command: wsdl2java -ant -impl -server -d outputDir myService.wsdl
The command does the following:
-
The -ant argument generates a Ant makefile, called build.xml , for your application.
-
The -impl argument generates a shell implementation class for each portType element in the WSDL document.
-
The -server argument generates a simple main() to launch your service as a stand alone application.
-
The -d outputDir argument tells wsdl2java to write the generated code to a directory called outputDir.
-
myService.wsdl is the WSDL document from which code is generated.
Generated code
Table1 describes the files generated for creating a service.
Table 1: Generated Classes for a Service
File |
Description |
---|---|
portTypeName.java |
The SEI. This file contains the interface your service implements. You should not edit this file. |
serviceName.java |
The endpoint. This file contains the Java class your clients will use to make requests on the service. |
portTypeNameImpl.java |
The skeleton implementation class. You will modify this file to implement your service. |
portTypeName_portTypeName... ImplPort_Server.java |
A basic server main() that allows you to deploy your service as a stand alone process. |