# `wsgen` Ant Task

## `wsgen` Task Overview

`wsgen` 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.

## Using `wsgen` Task

Before this task can be used, a `<taskdef>` element needs to be added to the project as given below:

    <taskdef name="wsgen" classname="com.sun.tools.ws.ant.WsGen">
        <classpath path="jaxws.classpath"/>
    </taskdef>

where `jaxws.classpath` is a reference to a path-like structure, defined elsewhere in the build environment, and contains the list of classes required by the JAX-WS tools.

### Environment Variables

- ANT_OPTS - command-line arguments that should be passed to the JVM. For example, you can define system properties or set the maximum Java heap size here.

### `wsgen` Task Attributes

The attributes and elements supported by the Ant task are listed below:

    <wsgen
            sei="..."
            destdir="directory for generated class files"
            classpath="classpath" | cp="classpath"
            resourcedestdir="directory for generated resource files such as WSDLs"
            sourcedestdir="directory for generated source files"
            keep="true|false"
            encoding="..."
            verbose="true|false"
            genwsdl="true|false"
            protocol="soap1.1|Xsoap1.2"
            servicename="..."
            portname="..."
            extension="true|false"
            inlineSchemas="true|false"
            fork="true|false"
            failonerror="true|false"
            xnocompile="true|false">
        <classpath refid="..."/>
        <externalmetadata file="..."/>
        <javacarg value="..."/>
        <jvmarg value="..."/>
    </wsgen>

Attribute | Description | Required | Command line
--- | --- | --- | ---
`sei` | Name of the service endpoint implementation class. | Yes. | SEI
`destdir` | Specify where to place output generated classes. | No. Defaults to current working directory. | `-d`
`classpath` | Specify where to find input class files. | One of these or nested `classpath` element. | `-classpath`
`cp` | Same as `-classpath`. | `-cp`
`resourcedestdir` | Used only in conjunction with the -wsdl option. Specify where to place generated resource files such as WSDLs. | No. Defaults to `destDir`. | `-r`
`sourcedestdir` | Specify where to place generated source files. | No. Defaults to current working directory. | `-s`
`encoding` | Set the encoding name for generated sources, such as UTF-8. | No. Defaults to platform default. | `-encoding`
`keep` | Keep generated files. | No. Defaults to false. | `-keep`
`verbose` | Output JAX_WS RI version and messages about what the compiler is doing. | No. Defaults to false. | `-verbose`
`genwsdl` | Specify that a WSDL file should be generated. | No. Defaults to false. | `-wsdl`
`protocol` | Used in conjunction with `genwsdl` to specify the protocol to use in the `wsdl:binding`. Value values are `"soap1.1"` or `"Xsoap1.2"`, default is `"soap1.1".` `"Xsoap1.2"` is not standard and can only be used in conjunction with the -extensions option. | No. Defaults to `-wsdl:soap11`. | `-wsdl[:protocol]`
`servicename` | Used in conjunction with the genwsdl option. Used to specify a particular `wsdl:service` name for the generated WSDL. Example:
    servicename="{http://mynamespace/}MyService"
| No. No defaults. | `-servicename`
`portname` | Used in conjunction with the genwsdl option. Used to specify a particular `wsdl:portname` name for the generated WSDL. Example:
    portname="{http://mynamespace/}MyPort"
| No. No defaults. | `-portname`
`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. | No. Defaults to false. | `-extension`
`inlineSchemas` | Used to inline schemas in a generated wsdl. Must be used in conjunction with the `wsdl` option. | No. Defaults to false. | `-inlineSchemas`
`fork` | Used to execute wsgen using forked VM. | No. Defaults to false. | None.
`failonerror` | Indicates whether errors will fail the build. | No. Defaults to true. | None.
`xnocompile` | Do not compile generated Java files. | No. Defaults to false. | `-Xnocompile`

The `classpath`/`cp` attribute is a path-like structure and can also be set via nested `<classpath>` elements.

### Nested Elements

`wsgen` supports the following nested element parameters.

#### `external-metadata`

An optional element `external-metadata` can be used if there are any web service metadata to be specified in xml file instead of java annotations:

    <wsgen
            resourcedestdir="${wsdl.dir}"
            sei="fromjava.server.AddNumbersImpl">
        <classpath refid="compile.classpath"/>
        <external-metadata file="metadata-AddNumbersImpl.xml"/>
    </wsgen>

For details see .

#### `javacarg`

The usage is similar to `<arg>` nested element, except that these arguments are directly passed to the Javac Compiler, which will be used for compiling sources generated during processing the referenced wsdl. For details about the syntax, see the relevant section in the Ant manual. Note: use '=' instead of space as a delimiter between option name and its value.

#### `jvmarg`

Use nested `<jvmarg>` elements to specify arguments for the the forked VM (ignored if fork is disabled), see the relevant section in the Ant manual.

## `wsgen` Task Examples

    <wsgen
            resourcedestdir="${wsdl.dir}"
            sei="fromjava.server.AddNumbersImpl">
        <classpath refid="compile.classpath"/>
    </wsgen>