Ant generates XML

Source: Internet
Author: User
Tags filegroup

Using Xmlbean to read and write XML files is very convenient, mainly through XML files generated XSD is called the Schema file, and then use Scomp (is the Xmlbean provided a compilation tool, it in the bin directory), through this tool, we can Schema file to generate Java Classes. This step to be implemented through ANT, it is very convenient and simple, as follows: (Be sure to add Jsr173_1.0_api.jar to the Ant directory in the Lib, otherwise, will be an error)

First define the Build.properties file:

Build.dir=classes

Jar.dir=jar

Xsd.dir=xsd

Xbean.dir=lib

This file mainly defines the names of some paths, which are easy to modify in the configuration file, the following is the Build.xml file:

<project default= "Build" basedir= "." >

<property file= "build.properties" description= "Transfer property from. properties File"/>

<taskdef name= "Xmlbean" classname= "Org.apache.xmlbeans.impl.tool.XMLBean" classpath= "${xbean.dir}/xbean.jar"/ >

<xmlbean classgendir= "${build.dir}" classpath= "${class.path}" failonerror= "true" >

<fileset dir= "${xsd.dir}" includes= "**/*.*"/>

</xmlbean>

<xmlbean schema= "${xsd.dir}" destfile= "${jar.dir}/schemas.jar"/>

</project>

The specific meaning of these can be found in:

Http://dev2dev.bea.com.cn/download/school/workshop/WorkshopCNHelp/doc/zh/core/index.html

Http://dev2dev.bea.com.cn/download/school/workshop/WorkshopCNHelp/doc/zh/core/index.html

Sample

Be sure to define the task in the script as follows:

				
						<taskdef name= "Xmlbean" classname= "Org.apache.xmlbeans.impl.tool.XMLBean" classpath= "Path/to/xbean.jar"/>
				
		

The following script generates all schemas in the schema directory and creates a jar file named Schemas.jar.

<xmlbean schema= "schemas" destfile= "Schemas.jar"/>

The following script compiles the Schema "ourschema.xsd" to the default Jar "Xmltypes.jar". If the remote URL defines any imports and includes, they will be downloaded during the build.

<xmlbean schema= "Schemas/ourschema.xsd" download= "true"/>

Working with filegroups

<xmlbean classgendir= "${build.dir}" classpath= "${class.path}"
Failonerror= "true" >
<fileset basedir= "src" excludes= "**/*.xsd"/>
<fileset basedir= "schemas" includes= "**/*.*"/>
</xmlbean>

Collects all files except XSD files in the SRC directory, as well as every file in the schemas directory, and compiles them.   A filegroup can include a schema file that references a schema component that was previously compiled.  Filegroups can also contain JAVA files. The Classpath parameter defines the classpath required to parse the compiled Schema and Java references.

The generated class will be transferred to ${build.dir}. Parameters

characteristic

Description

Required

Schema

A file that points to a single Schema file or file directory.   A non-path reference. If you need to generate multiple schema files at the same time, you should use nested filegroups instead of schema.

Yes, unless a filegroup element is nested.

DestFile

Defines the name of the jar file that is created. For example, "Myxmlbean.jar" outputs the results of the task to a jar with the same name.

No, default to "Xmltypes.jar".

Download

Set to True to allow the compiler to download URLs to import and include. The default is false, which means that all imported and included content must be replicated locally.

No, the default is False.

FailOnError

Determines whether the ant target will continue when the Xmlbean create process encounters a build error.

No, the default is true.

Verbose

Controls the output of the generated message.

No, the default is true.

Typesystemname

The name of the package in which the Typesystemholder class should be generated. The name should not normally be specified. Xmlbean will not be generated in this package. Use the. xsdconfig file to modify the Xmlbean package or class name.

Whether

Classgendir

Sets the location where the generated CLASS file is to be stored.

Whether

Srconly

A value of true means that only the source code is generated.

No, the default is False.

Srcgendir

Sets the location where the generated JAVA files are to be stored.

Whether

Classpath

The classpath to use if the schema in the filegroup will import the definition provided by the other compiled Xmlbean JAR file, or the JAVA file is in the Schema filegroup. In addition, nested classpath are supported.

Whether

Classpathref

Add a classpath as a reference to a path that is defined in another location.

Whether

Includes

A list of file modes that must be included, separated by commas or spaces. If omitted, all files will be included.

Whether

Includesfile

Filename. Each row of the file will be used as an include mode.

Whether

Excludes

A list of file modes that must be excluded, separated by commas or spaces. If omitted, no files are excluded (except for files excluded by default).

Whether

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.