如何在EclipseLink中创建JAXBContext?
JAXBContext.newInstance()
方法接收 Map
并将属性作为参数。
我应该指定哪些属性以及如何使 JAXBContext
实例了解多个具有 xml 映射的文件?
示例展示了如何以某种方式仅指定一个文件这在实际系统中是不可接受的(即使用new File(address)
)。相反,我需要使用返回 URL
对象的 classLoader.getResource()
。
谢谢!
UPD:
当我尝试实例化 JAXBContext 时,我收到此异常:
javax.xml.bind.JAXBException: property "eclipselink-oxm-xml" is not supported
at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:118)
...
很明显,启动时找不到 jaxb.properties 文件。我应该把它放在哪里? (我正在使用maven,实际上我尝试将其放入/target/jaxb.properties
,/target/classes/jaxb.properties
,/target/classes/META-INF/definitions/jaxb.properties
- 它靠近 xml 映射文件,而 /target/classes/com/myproject/experiment/jaxb.properties
- 它是靠近尝试实例化 JAXBContext 的类)。
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).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
EclipseLink JAXB (MOXy) 外部绑定文件可以位于任何(或列表中) of) 以下格式:
要使用 MOXy 作为 JAXB 提供程序,您还需要在模型类中包含一个名为 jaxb.properties 的文件,其中包含以下条目:
The EclipseLink JAXB (MOXy) external bindings file can be in any of (or a List of) the following formats:
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: