☰ See All Chapters |
wsgen
The JAX-WS SOAP Example we provided in the earlier chapters is just running in JVM, to deploy either service or client in app servers you have separate architecture to be followed. You have to generate ties for service and stubs for clients before packaging the application. wsimport, wsgen are the tools used to generate ties and stubs respectively.
You can find wsimport and wsgen tools from inside JDK installation.
The wsgen tool generates JAX-WS portable artifacts used in JAX-WS web services. The tool reads a web service endpoint class and generates all the required artifacts for web service deployment, and invocation. JAXWS 2.1.1 RI also provides a wsgen ant task, see Wsgen ant task for details.
Note:
wsgen tool is deprecated in Java 1.7, to work with wsgen tool we need Java 1.5/Java 1.6 and same should be in classpath.
wsgen tool will not work if the class has default package. To use wsgen tool class should have a package.
Syntax to execute wsgen command
wsgen [options] <SEI>
The following table lists the wsgen options.
Option | Description |
-classpath <path> | Specify where to find input class files |
-cp <path> | Same as -classpath <path> |
-d <directory> | Specify where to place generated output files |
-extension | allow vendor extensions (functionality not specified by the specification). Use of extensions may result in applications that are not portable or may not interoperate with other implementations |
-help | Display help |
-keep | Keep generated files |
-r <directory> | Used only in conjunction with the -wsdl option. Specify where to place generated resource files such as WSDLs |
-s <directory> | Specify where to place generated source files |
-verbose | Output messages about what the compiler is doing |
-version | Print version information. Use of this option will ONLY print version information. Normal processing will not occur. |
-wsdl[:protocol] | By default wsgen does not generate a WSDL file. This flag is optional and will cause wsgen to generate a WSDL file and is usually only used so that the developer can look at the WSDL before the endpoint is deploy. Theprotocol is optional and is used to specify what protocol should be used in the wsdl:binding. Valid protocols include: soap1.1 and Xsoap1.2. The default is soap1.1. Xsoap1.2 is not standard and can only be used in conjunction with the -extension option. |
-servicename <name> | Used only in conjunction with the -wsdl option. Used to specify a particular wsdl:service name to be generated in the WSDL. Example, -servicename "{https://mynamespace/}MyService" |
-portname <name> | Used only in conjunction with the -wsdl option. Used to specify a particular wsdl:port name to be generated in the WSDL. Example, -portname "{https://mynamespace/}MyPort" |
Example
wsgen -d stock -cp myclasspath stock.StockService
This will generate the wrapper classes needed for StockService annotated with @WebService annotation inside stockdirectory.
wsgen -wsdl -d stock -cp myclasspath stock.StockService
This will generate a SOAP 1.1 WSDL and schema for your Java class stock.StockService annotated with @WebService annotation.
wsgen -wsdl:Xsoap1.2 -d stock -cp myclasspath stock.StockService
Will generate a SOAP 1.2 WSDL.
Note that you do not have to generate WSDL at the development time as JAXWS runtime will automatically generate a WSDL for you when you deploy your service.
Please read our next tutorial to learn wsgen example.
All Chapters