简体   繁体   中英

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 (ie 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 E clipseLink 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM