How to create JAXBContext in EclipseLink?
JAXBContext.newInstance()
method receives Map
with properties as a parameter.
Which properties and how should I specify to make JAXBContext
instance informed about several files with xml-mappings?
Example shows how to specify only one file in a way which is not acceptable in real systems (i.e. with new File(address)
). Instead of this开发者_运维技巧 I need to use classLoader.getResource()
which returns URL
object.
Thanks!
UPD:
When I try to instantiate JAXBContext I get this exeption:
javax.xml.bind.JAXBException: property "eclipselink-oxm-xml" is not supported
at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:118)
...
It's obvious that jaxb.properties
file is not found at start up. Where should I put it? (I'm using maven, and actually I've tried to put it to /target/jaxb.properties
, /target/classes/jaxb.properties
, /target/classes/META-INF/definitions/jaxb.properties
- it's near xml-mapping file, and /target/classes/com/myproject/experiment/jaxb.properties
- it's near the class which tries to instantiate JAXBContext).
The EclipseLink JAXB (MOXy) external bindings file can be in any of (or a List of) the following formats:
- java.io.File
- java.io.InputStream
- java.io.Reader
- java.net.URL
- javax.xml.stream.XMLEventReader
- javax.xml.stream.XMLStreamReader
- javax.xml.transform.Source
- org.w3c.dom.Node
- org.xml.sax.InputSource
To use MOXy as your JAXB provider you also need to include a file named jaxb.properties with your model classes with the following entry:
javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory
精彩评论