Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Difference between revisions of "EclipseLink/UserGuide/MOXy/Runtime/Bootstrapping/JAXB properties"
Line 21: | Line 21: | ||
<source lang="java"> | <source lang="java"> | ||
− | DynamicJAXBContext jaxbContext = (DynamicJAXBContext) JAXBContext.newInstance(" | + | DynamicJAXBContext jaxbContext = (DynamicJAXBContext) JAXBContext.newInstance("example"); |
</source> | </source> |
Revision as of 13:31, 8 June 2011
EclipseLink MOXy
EclipseLink | |
Website | |
Download | |
Community | |
Mailing List • Forums • IRC • mattermost | |
Issues | |
Open • Help Wanted • Bug Day | |
Contribute | |
Browse Source |
Key API
Bootstrapping using jaxb.properties
The JAXB Specification supports another way of creating JAXBContexts; by specifying a factory class in a jaxb.properties file and then using the JAXBContext.newInstance() API. DynamicJAXBContexts can be created in this way as well.
First, we create a jaxb.properties file with the following contents, specifying our DynamicJAXBContextFactory as the factory used to build new JAXBContexts. Place the jaxb.properties file on your classpath in the package that your DynamicEntites will be generated in (in our example, the example package).
jaxb.properties
javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContextFactory
Now, you can use the newInstance(String contextPath) method to create a DynamicJAXBContext. When this method is called, MOXy attempts to locate a jaxb.properties file on the classpath in the package specified by contextPath, and use the specified factory.
DynamicJAXBContext jaxbContext = (DynamicJAXBContext) JAXBContext.newInstance("example");