Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Difference between revisions of "EclipseLink/Examples/MOXy/JaxbProperties"
m (→Example 2 - Class Array) |
m (linked to elug) |
||
Line 1: | Line 1: | ||
JAXB is a standard that allows many underlying implementations. The standard way to specify which JAXB implementation should be used is through a file called jaxb.properties. This file contains one property. To specify that the EclipseLink JAXB implementation should be used the jaxb.properties file should have the following content: | JAXB is a standard that allows many underlying implementations. The standard way to specify which JAXB implementation should be used is through a file called jaxb.properties. This file contains one property. To specify that the EclipseLink JAXB implementation should be used the jaxb.properties file should have the following content: | ||
+ | |||
+ | javax.xml.bind.context.factory=org.eclipse.persistence.ox.jaxb.JAXBContextFactory | ||
+ | |||
+ | |||
+ | See [[Introduction_to_XML_Projects_%28ELUG%29#EclipseLink_Support_for_Java_Architecture_for_XML_Binding_.28JAXB.29|EclipseLink Support for Java Architecture for XML Binding (JAXB)]] in the EclipseLink User's Guide for more information. | ||
+ | |||
− | |||
== Example 1 - Context Path == | == Example 1 - Context Path == | ||
Line 8: | Line 13: | ||
'''Code Example''' | '''Code Example''' | ||
− | + | JAXBContext.newInstance("com.example.model"); | |
+ | |||
+ | |||
== Example 2 - Class Array == | == Example 2 - Class Array == | ||
Line 15: | Line 22: | ||
'''Code Example''' | '''Code Example''' | ||
− | + | Class[] classes = new Class[4]; | |
− | + | classes[0] = com.example.model.AddressType.class; | |
− | + | classes[1] = com.example.model.ContactInfo.class; | |
− | + | classes[2] = com.example.model.CustomerType.class; | |
− | + | classes[3] = com.example.model.PhoneNumber.class; | |
− | + | JAXBContext jaxbContext = JAXBContext.newInstance(classes); |
Revision as of 09:32, 14 December 2007
JAXB is a standard that allows many underlying implementations. The standard way to specify which JAXB implementation should be used is through a file called jaxb.properties. This file contains one property. To specify that the EclipseLink JAXB implementation should be used the jaxb.properties file should have the following content:
javax.xml.bind.context.factory=org.eclipse.persistence.ox.jaxb.JAXBContextFactory
See EclipseLink Support for Java Architecture for XML Binding (JAXB) in the EclipseLink User's Guide for more information.
Example 1 - Context Path
If a context path is used to create the JAXBContext then the corresponding jaxb.properties file must be available on the class path in the corresponding package.
Code Example
JAXBContext.newInstance("com.example.model");
Example 2 - Class Array
If a class array is used to create the JAXBContent then the corresponding jaxb.properties file must be available on the class path in the package corresponding to the package of the model classes. In the example below the corresponding package is "com.example.model".
Code Example
Class[] classes = new Class[4]; classes[0] = com.example.model.AddressType.class; classes[1] = com.example.model.ContactInfo.class; classes[2] = com.example.model.CustomerType.class; classes[3] = com.example.model.PhoneNumber.class; JAXBContext jaxbContext = JAXBContext.newInstance(classes);