background image

Create Marshal Example

<< External Customize Example | XmlAccessorOrder Example >>
<< External Customize Example | XmlAccessorOrder Example >>

Create Marshal Example

If you are using JDK 6, perform the following steps before you run any of the Java-to-Schema
examples:
1. Change to one of the Java-to-Schema example directories (for example,
tut-install/javaeetutorial5/examples/jaxb/j2s-create-marshal.
2. Run the following Ant command:
ant update-endorsed
This command creates an endorsed directory in the JDK and copies the
webservices-api.jar
file from the Application Server's lib/endorsed/ directory into it.
Create Marshal Example
The Create Marshal example illustrates Java-to-schema databinding. It demonstrates
marshalling and unmarshalling of JAXB annotated classes and also shows how to enable JAXP
1.3 validation at unmarshal time using a schema file that was generated from the JAXB mapped
classes.
The schema file, bc.xsd, was generated with the following commands:
schemagen src/cardfile/*.java
cp schema1.xsd bc.xsd
Note that schema1.xsd, was copied to bc.xsd; schemagen does not allow you to specify a
schema name of your choice.
Building and Running the Create Marshal Example Using NetBeans IDE
Follow these instructions to build and run the Create Marshal example on your Application
Server instance using the NetBeans IDE.
1. In NetBeans IDE, select File
Open Project.
2. In the Open Project dialog, navigate to tut-install/javaeetutorial5/examples/jaxb/.
3. Select the j2s-create-marshal folder.
4. Select the Open as Main Project check box.
5. Click Open Project Folder.
6. Right-click the j2s-create-marshal project and select Run Project.
Building and Running the Create Marshal Example Using Ant
To compile and run the Create Marshal example using Ant, in a terminal window, go to the
tut-install/javaeetutorial5/examples/jaxb/j2s-create-marshal/ directory and type the
following:
Java-to-Schema Examples
Chapter 17 · Binding between XML Schema and Java Classes
537