简体   繁体   English

如何在EclipseLink中创建JAXBContext?

[英]How to create JAXBContext in EclipseLink?

JAXBContext.newInstance() method receives Map with properties as a parameter. JAXBContext.newInstance()方法接收带有属性作为参数的Map

Which properties and how should I specify to make JAXBContext instance informed about several files with xml-mappings? 我应该指定哪些属性以及如何使用xml-mappings通知JAXBContext实例几个文件?

Example shows how to specify only one file in a way which is not acceptable in real systems (ie with new File(address) ). 示例显示了如何以实际系统中不可接受的方式(即使用new File(address) )仅指定一个文件。 Instead of this I need to use classLoader.getResource() which returns URL object. 而不是这个我需要使用classLoader.getResource()返回URL对象。

Thanks! 谢谢!

UPD: UPD:

When I try to instantiate JAXBContext I get this exeption: 当我尝试实例化JAXBContext时,我得到了这个例子:

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. 很明显,启动时找不到jaxb.properties文件。 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). (我使用maven,实际上我试图把它放到/target/jaxb.properties/target/classes/jaxb.properties/target/classes/META-INF/definitions/jaxb.properties -这是近xml-mapping文件和/target/classes/com/myproject/experiment/jaxb.properties - 它靠近尝试实例化JAXBContext的类。

The E clipseLink JAXB (MOXy) external bindings file can be in any of (or a List of) the following formats: E clipseLink JAXB(MOXy)外部绑定文件可以是以下格式中的任何一种(或列表):

  • java.io.File 的java.io.File
  • java.io.InputStream 的java.io.InputStream
  • java.io.Reader java.io.Reader中
  • java.net.URL 的java.net.URL
  • javax.xml.stream.XMLEventReader javax.xml.stream.XMLEventReader
  • javax.xml.stream.XMLStreamReader javax.xml.stream.XMLStreamReader
  • javax.xml.transform.Source javax.xml.transform.Source
  • org.w3c.dom.Node org.w3c.dom.Node中
  • org.xml.sax.InputSource 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: 要将MOXy用作JAXB提供程序,还需要在模型类中包含名为jaxb.properties的文件,其中包含以下条目:

javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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