Download the "Examples Zip" from the EclipseLink [http://www.eclipse.org/eclipselink/downloads/ Downloads] page. Code for this example will be found in the <tt>org.eclipse.persistence.example.jaxb.zip</tt> file.

Download the "Examples Zip" from the EclipseLink [http://www.eclipse.org/eclipselink/downloads/ Downloads] page. Code for this example will be found in the <tt>org.eclipse.persistence.example.jaxb.zip</tt> file.

Click "Browse" to select a root directory, and point to the folder containing this example. After selecting the directory, you should see the project name in the "Projects" list. Click "Finish".

This project is configured to use a classpath variable, ECLIPSELINK_JLIB, to point to the required JAR files. After the project is imported, you should define a variable called ECLIPSELINK_JLIB to point to your EclipseLink jlib directory.

Running the JAXB Compiler

The JAXB compiler can be run to generate JAXB-annotated Java classes from an XML Schema:

In this example, the JAXB Compiler is run from the "run.jaxb.compiler" task in the ANT build file.

Creating a JAXBContext using jaxb.properties

The standard way to specify which JAXB implementation should be used is through a file called jaxb.properties, which contains a single property, javax.xml.bind.context.factory. This file must be available on the classpath in the corresponding package (in this example, "org.example.customer_example"). To specify that the EclipseLink JAXB implementation should be used, your jaxb.properties file should have the following content:

Note the use of the ObjectFactory class to create a new PhoneNumber object. In addition to generating the model classes used in this example, the JAXB compiler also generates an ObjectFactory class that can be used to create any of the generated types.