Compile a set of XSDs and/or WSDLs into xbeans. This is useful for building an XMLBean jar from .XSD and .WSDL files. The task can also generate the source code that makes up the xbean type system specified by the schema files if desired.
Note: This task depends on an external library not included in
the Ant distribution called xbean.jar. It can be found in the XMLBeans
developer kit at http://dev2dev.bea.com/technologies/xmlbeans/.
The build script will need to include a taskdef for xmlbean, which could look
like this:
<taskdef name="xmlbean" classname="org.apache.xmlbeans.impl.tool.XMLBean" classpath="path/to/xbean.jar"/>
It is possible to refine the set of files that are being processed. This can be done with the includes, includesfile, excludes, excludesfile and defaultexcludes attributes. With the includes or includesfile attribute you specify the files you want to have included by using patterns. The exclude or excludesfile attribute is used to specify the files you want to have excluded. This is also done with patterns. And finally with the defaultexcludes attribute, you can specify whether you want to use default exclusions or not. See the section on directory based tasks, on how the inclusion/exclusion of files works, and how to write patterns.
This task forms an implicit FileSet
and supports all attributes of <fileset>
(dir
becomes basedir
) as well as the nested <include>
,
<exclude>
and <patternset>
elements.
Attribute | Description | Required |
schema | A file that points to either an individual schema file or a directory of files. Not a path reference. If multiple schema files need to be built together, use a nexted fileset instead of setting schema. | Yes, unless a fileset element is nested. |
destfile | Define the name of the jar file created. For instance, "myXMLBean.jar" will output the results of this task into a jar with the same name. | No, default is "xmltypes.jar". |
download | Set to true to permit the compiler to download
URLs for imports and includes. Defaults to false, meaning all imports
and includes must be copied locally. |
No, default is false. |
failonerror | Determines whether or not the ant target
will continue if the XMLBean creation encounters a build error. |
No, default is true. |
verbose |
Controls the amount of build message output. |
No, default is true. |
typesystemname |
The name of the package that the TypeSystemHolder
class should be generated in. Normally this should be left unspecified.
None of the xml beans are generated in this package. Use .xsdconfig files
to modify xml bean package or class names. |
No |
classgendir |
Set a location to generate .class files into. |
No |
srconly |
A value of true means that only source will be generated. |
No, default is false. |
srcgendir |
Set a location to generate .java files into. |
No |
classpath | The classpath to use if schemas in the fileset import definitions that are supplied by other compiled xml beans JAR files, or if .java files are in the schema fileset. Also supports a nested classpath. | No |
classpathref | Adds a classpath, given as reference to a path defined elsewhere. | No |
includes | Comma- or space-separated list of patterns of files that must be included. All files are included when omitted. | No |
includesfile | The name of a file. Each line of this file is taken to be an include pattern | No |
excludes | Comma- or space-separated list of patterns of files that must be excluded. No files (except default excludes) are excluded when omitted. | No |
excludesfile | The name of a file. Each line of this file is taken to be an exclude pattern | No |
defaultexcludes | Indicates whether default excludes should be used or not ("yes"/"no"). Default excludes are used when omitted. | No |
debug | Indicates whether source should be compiled with
debug information; defaults to off . If set to
off , -g:none will be passed on the
command line for compilers that support it (for other compilers, no
command line argument will be used). If set to true ,
the value of the debuglevel attribute determines the
command line argument. |
No |
debuglevel | Keyword list to be appended to the -g
command-line switch. This will be ignored by all implementations except
modern and classic(ver >= 1.2) .
Legal values are none or a comma-separated list of the
following keywords:
lines , vars , and source .
If debuglevel is not specified, by default,
nothing will be
appended to -g . If debug is not turned on,
this attribute will be ignored.
|
No |
optimize | Indicates whether source should be compiled with
optimization; defaults to off . |
No |
includeAntRuntime | Whether to include the Ant run-time libraries in the
classpath; defaults to yes . |
No |
includeJavaRuntime | Whether to include the default run-time
libraries from the executing VM in the classpath;
defaults to no . |
No |
fork | Whether to execute javac using the
JDK compiler externally; defaults to yes . |
No, default is true |
executable | Complete path to the javac
executable to use in case of fork="yes" .
Defaults to the compiler of the Java version that is currently
running Ant. Ignored if fork="no" |
No |
memoryInitialSize | The initial size of the memory for the underlying VM,
if javac is run externally; ignored otherwise. Defaults
to the standard VM memory setting.
(Examples: 83886080 , 81920k , or
80m ) |
No |
memoryMaximumSize | The maximum size of the memory for the underlying VM,
if javac is run externally; ignored otherwise. Defaults
to the standard VM memory setting.
(Examples: 83886080 , 81920k , or
80m ) |
No |
compiler | The compiler implementation to use.
If this attribute is not set, the value of the
build.compiler property, if set, will be used.
Otherwise, the default compiler for the current VM will be used.
| No |
Be sure to define the task in your script, like this:
<taskdef name="xmlbean" classname="org.apache.xmlbeans.impl.tool.XMLBean" classpath="path/to/xbean.jar"/>Builds all the schemas in the schemas directory and creates a jar called 'Schemas.jar'.
<xmlbean schema="schemas" destfile="Schemas.jar"/>
<xmlbean schema="schemas/ourSchema.xsd" download="true"/>Compiles the schema 'ourShema.xsd' into the default jar 'xmltypes.jar'. If any imports and includes are defined by remote URLs, they are downloaded during the build.
Using a fileset
<xmlbean classgendir="${build.dir}" classpath="${class.path}"Gathers all the files in the 'src' directory except .xsd files, along with every file in the 'schemas' directory and compiles them. The fileset can include schema files that refer to previously compiled schema components. The fileset can also contain .java files. The classpath parameter defines the classpath necessary to resolve compiled schema and java references.
failonerror="true">
<fileset basedir="src" excludes="**/*.xsd"/>
<fileset basedir="schemas" includes="**/*.*"/>
</xmlbean>
The built classes will go into ${build.dir}.