Schema2Java translates an XML Schema description of structures into Java classes.
Schema2Java is included in the Core-Tools component (please see Core-Tools in the Components chapter). It is accessible through the Schema2Java script in the bin subdirectory of the WSO2 SOA Enablement Server distribution.
![]() | Note |
---|---|
Instead of manually typing out the command line each time you run Schema2Java, you can create an ANT task build script that can be reused. Please see ANT Schema2Java Task for details. |
The Schema2Java tool can process both local XML Schema documents and those located remotely by their URL, as follows:
Schema2Java interfaces.xsd
Schema2Java http://localhost:6060/Service/interfaces.xsd
An unlimited number of xsd files can be specified in this manner.
Schema2Java input1.xsd ... inputN.xsd
The Schema2Java tool has many parameters that adjust the compilation process. They can be divided into the categories shown in Table 1.
Table 19. Schema2Java Parameter Categories
Category | Comments | Parameters |
---|---|---|
commands for selecting input | Selects the part of the WSDL document to be generated. | --deployment-descriptor --processing |
Options for selecting output | Selects the destination directory, Java packages and format of generated classes. | --force/-f --generate-javabeans --generate-interfaces --map-type/-m --map-ns/-n --output-directory/-d --structure-package/-s --strict-schema --mixed-to-dom |
Debugging options | Finds a problem if WSDL file is compiled incorrectly. | --verbose[=0-10]/-v[0-10] --version --print-types |
There are two parameters for customizing the generation process:
Sets the deployment descriptor that describes additional XML schemas/type mapping to be used for processing the XML Schema document. When this option is used, --processing must be used as well. (Please see Deployment Descriptors)
Sets the processing in the deployment descriptor that describes additional XML schemas/type mapping to be used for processing the XML Schema document. If this option is used, --deployment-descriptor must be used as well (see above). This parameter is mostly used for custom serialization. (For more information about serialization frameworks, please see Java Level Processing.) An example follows:
Schema2Java --deployment-descriptor package.xml --processing TypeMappingStructures.xsd
The output parameters of the Schema2Java tool let the user control the type of file to be generated in addition to its destination. The options are:
Overwrites existing file, when a file with the same path as the file being generated exists already. This prevents "File already exists"-type errors.
The default mode for generating structures is via creating all public fields into a class. This option switches to a mode where the fields are protected and public get/set methods are generated as well, conforming to the Java Beans compatibility mode.
The default mode for generating structures is via making all public fields into a class. This option switches to a mode where only an interface for the actual implementation is generated. The user must provide an implementation of the interface, and create custom (de)serializers for these types.
Specifies type mapping from a schema type named {ns}local to a Java class, where ns is the namespace, local is the name of the schema type from that namespace and javaName is the fully qualified name of the Java class. Example:
Schema2Java -m {http://some.org}Order->org.myorg.BasicOrder Some.xsd
Specifies mapping from schema namespace to java package
The output directory where the Java files are to be generated. If the directory does not exist, it is created.
The package in which generated classes (structures) will be placed.
For better interoperability with Microsoft .NET, WSO2 SOA Enablement Server Server Schema2Java optimizes the XML Schema file. The structures so generated do not strictly conform to XML Schema. This behavior can be switched off using this option.
Map XML Schema types with mixed content to org.w3c.dom.Element.
The debugging options let you test the process of generating a Java class from the target XML Schema. The options are as follows:
Controls verbose output. The optional parameter (default value 0) is the level of verbose messages (0: no messages, 10: full messages).
Shows the version of the Schema2Java tool. Use this option when reporting potential Schema2Java bugs.