CodeGen toolCodeGen is the tool used to generate Java code and a binding definition from an XML schema. It currently handles most types of schema definitions, but as with most data binding tools some aspects of schema with are not completely supported. These unsupported or partially-supported schema features including the following:
Running CodeGenCodeGen 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 The CodeGen application main class is Here's a sample of running CodeGen on Unix/Linux systems from the examples/codegen directory of the distribution (in a single line, shown split here only for formatting): java -cp ../../lib/jibx-tools.jar org.jibx.schema.codegen.CodeGen otasubset/OTA_AirLowFareSearchRQ.xsd On Windows, the corresponding command line is: java -cp ..\..\lib\jibx-tools.jar org.jibx.schema.codegen.CodeGen otasubset\OTA_AirLowFareSearchRQ.xsd By default, CodeGen output just goes to the current directory where it was executed. The generated root binding definition is named binding.xml, and the generated Java package(s) is derived from the schema namespace. When working with large schemas you may find performance to be a problem using the
standard JVM memory settings. You should be able to dramatically improve performance by
increasing your Java runtime memory settings (with the JVMs provided by Sun this is done
using the -Xms and -Xmx command line flags, so passing the command line
parameters Using build toolsYou can easily run CodeGen from an Ant build, just as you would any other Java application. The build.xml in the examples/codegen directory gives an example of this (which passes an optional generation directory path parameter, in addition to a schema file path pattern), as shown below: <!-- set classpath for compiling and running application with JiBX --> <path id="classpath"> <fileset dir="${jibx-home}/lib" includes="*.jar"/> <pathelement location="bin"/> </path> ... <!-- generate using default settings --> <target name="codegen" depends="check-runtime,clean"> <echo message="Running code generation from schema"/> <java classname="org.jibx.schema.codegen.CodeGen" fork="yes" classpathref="classpath" failonerror="true"> <arg value="-t"/> <arg value="gen/src"/> <arg value="otasubset/OTA_AirLowFareSearch*.xsd"/> </java> </target> Most IDEs allow you to directly execute an Ant build target, so you can use the Ant approach to running CodeGen from within your IDE. You can change the default memory size for the <java> Ant task using nested <jvmarg> parameters. By way of example, here's how you'd change the above Ant target to use 512 megabytes of memory: <java classname="org.jibx.schema.codegen.CodeGen" fork="yes" classpathref="classpath" failonerror="true"> <jvmarg value="-Xms512M"/> <jvmarg value="-Xmx512M"/> <arg value="-t"/> <arg value="gen/src"/> <arg value="otasubset/OTA_AirLowFareSearch*.xsd"/> </java> Command line parametersYou can pass a variety of command line parameters to CodeGen, as listed below in alphabetical order:
You need to specify one or more schema paths or file path patterns as command line parameters to CodeGen. Each schema you specify is used as a starting point for generating code and binding definitions. CodeGen examines each specified schema to find references to other schemas, and then recursively examines the referenced schemas, to find the complete set of schemas used to represent the data. It then generates code and binding definitions for all of these schemas. The schema names or file path patterns must be at the end of the command line, following any other command line parameters. '*' wildcard characters can be used in schema names, but only as part of file paths. Schema names can also be specified using HTTP or other forms of URLs, but wildcard characters are not allowed in this case. Finally, you can pass global customizations to CodeGen as command-line parameters,
by using Logging supportCodeGen includes logging code at a variety of levels of detail, using the log4j library. The jibx-tools.jar includes a default log4j.properties which only supports ERROR level logging, with output to the console. This default properties file can be overridden by another log4j.properties which is placed earlier in the classpath. The log4j.properties file in the examples/codegen directory is supplied as a sample, which can be activated by changing the classpath definition in the Ant build.xml as follows: <!-- set classpath for compiling and running application with JiBX --> <path id="classpath"> <pathelement location="."/> <fileset dir="${jibx-home}/lib" includes="*.jar"/> <pathelement location="bin"/> </path> This logging support is only intended for use by JiBX developers and others who are investigating the operation of the CodeGen program. The logging information is generally not useful to end users. |