1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>JiBX: BindGen Tool</title>
</head>
<body class="composite">
<div id="bodycol">
<div class="app">
<div class="h3">
<h3><a name="intro"></a>BindGen tool</h3>
<p>BindGen is the tool used to generate a binding definition and matching schema
definition from existing Java code.</p>
</div>
<div class="h3">
<h3>Running BindGen</h3>
<p>BindGen 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 <code><java></code> task, discussed below). However it's being run, you need
to include <i>jibx-tools.jar</i> from your JiBX installation <i>lib</i> 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 <i>lib</i>
directory (including <i>jibx-bind.jar</i>, <i>jibx-schema.jar</i>, and <i>jibx-run.jar</i>).
As long as these jars are in the same directory as <i>jibx-tools.jar</i> you don't need to
list them in the classpath, though - they'll be picked up automatically.</p>
<p>The BindGen application main class is <code>org.jibx.binding.generator.BindGen</code>,
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.</p>
<p>Here's a sample of running BindGen on Unix/Linux systems from the <i>examples/bindgen</i>
directory of the distribution (in a single line, shown split here only for formatting):</p>
<div id="source"><pre>java -cp ../../lib/jibx-tools.jar:bin org.jibx.binding.generator.BindGen
org.jibx.starter1.Order</pre></div>
<p>On Windows, the corresponding command line is:</p>
<div id="source"><pre>java -cp ..\..\lib\jibx-tools.jar;bin org.jibx.binding.generator.BindGen
org.jibx.starter.Order</pre></div>
<p>By default, BindGen output just goes to the current directory where it was executed. The
generated root binding definition is named <i>binding.xml</i>, and the generated schema
name is derived from the target namespace (which in turn is derived from the Java package
name).</p>
</div>
<div class="h3">
<h3>Using build tools</h3>
<p>You can easily run BindGen from an Ant build, just as you would any other Java application.
The <i>build.xml</i> in the <i>examples/bindgen</i> directory gives an example of this
(which passes an optional source directory path parameter, in addition to a root class name),
as shown below:</p>
<div id="source"><pre> <!-- set classpath for compiling and running application with JiBX -->
<path id="classpath">
<fileset dir="${jibx-home}/lib" includes="*.jar"/>
<pathelement location="bin"/>
</path>
...
<!-- generate default binding and schema -->
<target name="bindgen">
<echo message="Running BindGen tool"/>
<java classpathref="classpath" fork="true" failonerror="true"
classname="org.jibx.binding.generator.BindGen">
<arg value="-s"/>
<arg value="src"/>
<arg value="org.jibx.starter1.Order"/>
</java>
</target>
</pre></div>
<p>Most IDEs allow you to directly execute an Ant build target, so you can use the Ant
approach to running BindGen from within your IDE.</p>
</div>
<div class="h3">
<h3>Command line parameters</h3>
<p>You can pass a variety of command line parameters to BindGen, as listed below in
alphabetical order:</p>
<table cellpadding="3" cellspacing="2" border="1" width="100%">
<tr class="b">
<th scope="col">Parameter</th>
<th scope="col">Purpose</th>
</tr>
<tr class="a">
<td><code>-a</code></td>
<td>Force abstract mapping (equivalent to a schema complexType) generation for classes
passed as input parameters.</td>
</tr>
<tr class="b">
<td><code>-b name</code></td>
<td>Generated root binding definition file name (default name is binding.xml)</td>
</tr>
<tr class="a">
<td><code>-c path</code></td>
<td>Path to input customizations file</td>
</tr>
<tr class="b">
<td><code>-m</code></td>
<td>Force concrete mapping (equivalent to a schema complexType plus an element of that
type) generation for classes passed as input parameters</td>
</tr>
<tr class="a">
<td><code>-n uri=name,...</code></td>
<td>Give schema namespace URI and file-name pairs (default generates file names from
schema namespace URIs)</td>
</tr>
<tr class="b">
<td><code>-o</code></td>
<td>Binding generation only (no schema generation)</td>
</tr>
<tr class="a">
<td><code>-p path,...</code></td>
<td>Paths for loading Java class files (default is the classpath used to run BindGen)</td>
</tr>
<tr class="b">
<td><code>-s path,...</code></td>
<td>Paths for loading Java source files (source is not used by default)</td>
</tr>
<tr class="a">
<td><code>-t path</code></td>
<td>Target directory path for generated output (default is current directory)</td>
</tr>
<tr class="b">
<td><code>-v</code></td>
<td>Verbose output</td>
</tr>
<tr class="a">
<td><code>-w</code></td>
<td>Wipe all files from target directory before generating output (ignored if the target directory is the same as the current directory)</td>
</tr>
</table>
<p>You need to specify one or more class names as command line parameters to
BindGen. Each class you name is used as a starting point for generating binding
definitions. BindGen examines each class listed to find references to other classes,
and then recursively examines the referenced classes, to find the complete set of
classes necessary to represent your data. It then generates binding and schema
definitions for all of these classes. The class names must be at the end of the command
line, following any other command line parameters.</p>
<p>You can pass global customizations to BindGen as command-line parameters,
by using <code>--</code> as a special prefix to the customization attribute name.
This is explained in more detail in the BindGen <a href="%bgcustoms%#command">customization
reference page</a>. Before digging into the details of customizations you may find
it useful to review the BindGen <a href="%bgexamples%">examples</a> to learn how BindGen
works and see some basic applications of customizations.</p>
</div>
</div>
</div>
</body>
</html>
|