Jibx2Wsdl tool

Jibx2Wsdl is the tool used to generate a binding definition and matching WSDL and schema definitions from existing Java code. It includes support for Java 5 enumerations and typed collections, JavaDoc extraction for use in service definitions, and all the data model customizations of BindGen. Jibx2Wsdl allows you to expose existing code as web services using Axis2 and JiBX data binding, while retaining the flexibility to modify your data model and adjust the JiBX bindings so that the XML is unchanged. Alternatively, you can just generate a WSDL and schema using Jibx2Wsdl and throw away the JiBX binding definitions, using the generated WSDL and schema as a quick start on a start-from-WSDL approach. The generated doc/lit wrapped WSDLs are compatible with Apache Axis2 and other major web service frameworks.

Running Jibx2Wsdl

Jibx2Wsdl executes as a Java application, meaning it needs to be run directly from a console window using the "java" command, or though some equivalent technique (such as an Ant <java> task, discussed below). However it's being run, you need to include jibx-tools.jar from your JiBX installation lib directory in the Java classpath, along with the path for the compiled class files you'll use as input to the generation. You'll also need several of the other jars from the JiBX lib directory (including jibx-bind.jar, jibx-schema.jar, and jibx-run.jar). As long as these jars are in the same directory as jibx-tools.jar you don't need to list them in the classpath, though - they'll be picked up automatically.

The Jibx2Wsdl application main class is org.jibx.ws.wsdl.tools.Jibx2Wsdl, and it takes as parameters the fully-qualified names of one or more root class(es) to be to be included in the binding generation. In schema terms, each of these root classes will be treated as a separate global definition.

Here's a sample of running Jibx2Wsdl on Unix/Linux systems from the examples/jibx2wsdl/example1 directory of the distribution (in a single line, shown split here only for formatting):

java -cp ../../../lib/jibx-tools.jar:start/bin org.jibx.ws.wsdl.tools.Jibx2Wsdl
 com.sosnoski.ws.library.jibx2wsdl.BookServer1

On Windows, the corresponding command line is:

java -cp ..\..\..\lib\jibx-tools.jar;start\bin org.jibx.ws.wsdl.tools.Jibx2Wsdl
 com.sosnoski.ws.library.jibx2wsdl.BookServer1

By default, Jibx2Wsdl output just goes to the current directory where it was executed. The generated root binding definition is named binding.xml, and the generated WSDL and schema name is derived from the target namespace (which in turn is derived from the Java package name).

Using build tools

You can easily run Jibx2Wsdl from an Ant build, just as you would any other Java application. The build.xml in the examples/jibx2wsdl/example1 directory gives an example of this (which passes an optional source directory path parameter, in addition to a root class name), as shown below:

  <path id="jibx-classpath">
    <fileset dir="${jibx-home}/lib" includes="**/*.jar"/>
    <pathelement location="bin"/>
  </path>
  ...
  <!-- Generate bindings, schemas, and WSDL -->
  <target name="generate-wsdl" depends="compile-starter">
    <delete quiet="true" dir="${basedir}/gen"/>
    <mkdir dir="${basedir}/gen"/>
    <echo message="Running Jibx2Wsdl tool"/>
    <java classpathref="jibx-classpath"
        classname="org.jibx.ws.wsdl.tools.Jibx2Wsdl" fork="true" failonerror="true">
      <arg value="-p"/>
      <arg value="${basedir}/start/bin"/>
      <arg value="-s"/>
      <arg value="${basedir}/start/src"/>
      <arg value="-t"/>
      <arg value="${basedir}/gen"/>
      <arg value="--strip-prefixes=m_"/>
      <arg value="com.sosnoski.ws.library.jibx2wsdl.BookServer1"/>
    </java>
  </target>

Most IDEs allow you to directly execute an Ant build target, so you can use the Ant approach to running Jibx2Wsdl from within your IDE.

Command line parameters

You can pass a variety of command line parameters to Jibx2Wsdl, as listed below in alphabetical order:

Parameter Purpose
-b name Generated root binding definition file name (default name is binding.xml)
-c path Path to input customizations file
-d Use pure doc/lit style (rather than the wrapped style default, where individual method parameters are combined to form a request message). When this flag is used, each service method must take only one parameter. The XML representation of that parameter is used directly as the request message for the operation, and the XML representation of the return value is used directly as the response message for the operation.
-n uri=name,... Schema namespace URI and file name pairs (default generates file names from URIs)
-p path,... Paths for loading Java class files (default is the classpath used to run Jibx2Wsdl)
-s path,... Paths for loading Java source files (source is not used by default)
-t path Target directory path for generated output (default is current directory)
-u binding,...;schema,... Use existing bindings and schemas. This allows specifying one or more bindings and one or more schemas to be used for WSDL generation. The supplied bindings and schema definitions are used for service method parameter and return values with matching types, and any schemas containing definitions used are copied into the target directory for direct reference from the generated WSDL.
-v Verbose output
-w Wipe all files from target directory before generating output (ignored if the target directory is the same as the current directory)
-x class,... Names of extra classes to be included in the binding and schema generation (useful when the service definition class methods use interfaces or abstract classes as parameter types)

You need to specify one or more service definition class names as command line parameters to Jibx2Wsdl. Each class you name is used as a starting point for generating service definitions. Jibx2Wsdl examines each class listed to find methods to be exposed as web service operations. Each parameter type passed to a service method, or result type returned from a method, is then included in the binding and schema generation. These are recursively examined to find the complete set of classes necessary to represent your data. Jibx2Wsdl then generates binding and schema definitions for all of these classes. The service definition class names must be at the end of the command line, following any other command line parameters.

You can pass global customizations to Jibx2Wsdl as command-line parameters, by using -- as a special prefix to the customization attribute name. This is explained in more detail in the Jibx2Wsdl customization reference page. Before digging into the details of customizations you may find it useful to review the Jibx2Wsdl examples to learn how Jibx2Wsdl works and see some basic applications of customizations.