10.12.2012 Views

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

If you are using JDK 6, perform the following steps before you run any of the <strong>Java</strong>-to-Schema<br />

examples:<br />

1. Change to one of the <strong>Java</strong>-to-Schema example directories (for example,<br />

tut-install/javaeetutorial5/examples/jaxb/j2s-create-marshal.<br />

2. Run the following Ant command:<br />

ant update-endorsed<br />

This command creates an endorsed directory in the JDK and copies the<br />

webservices-api.jar file from the Application Server's lib/endorsed/ directory into it.<br />

Create Marshal Example<br />

<strong>The</strong> Create Marshal example illustrates <strong>Java</strong>-to-schema databinding. It demonstrates<br />

marshalling and unmarshalling of JAXB annotated classes and also shows how to enable JAXP<br />

1.3 validation at unmarshal time using a schema file that was generated from the JAXB mapped<br />

classes.<br />

<strong>The</strong> schema file, bc.xsd, was generated with the following commands:<br />

schemagen src/cardfile/*.java<br />

cp schema1.xsd bc.xsd<br />

Note that schema1.xsd, was copied to bc.xsd; schemagen does not allow you to specify a<br />

schema name of your choice.<br />

Building and Running the Create Marshal Example Using NetBeans IDE<br />

Follow these instructions to build and run the Create Marshal example on your Application<br />

Server instance using NetBeans IDE.<br />

1. In NetBeans IDE, select File→Open Project.<br />

2. In the Open Project dialog, navigate to tut-install/javaeetutorial5/examples/jaxb/.<br />

3. Select the j2s-create-marshal folder.<br />

4. Select the Open as Main Project check box.<br />

5. Click Open Project.<br />

6. Right-click the j2s-create-marshal project and select Run.<br />

Building and Running the Create Marshal Example Using Ant<br />

<strong>Java</strong>-to-Schema Examples<br />

To compile and run the Create Marshal example using Ant, in a terminal window, go to the<br />

tut-install/javaeetutorial5/examples/jaxb/j2s-create-marshal/ directory and type the<br />

following:<br />

Chapter 17 • Binding between XML Schema and <strong>Java</strong> Classes 535

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!