问题描述
我正在尝试使用MOXy作为我的JAXB提供程序,以便将内容编组/解组成XML / JSON。
I am trying to use MOXy as my JAXB provider in order to marshal/unmarshal content into XML/JSON.
我创建了jaxb.properties文件as as content: javax.xml.bind.context.factory = org.eclipse.persistence.jaxb.JAXBContextFactor
I have created the "jaxb.properties" file with as content : javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactor
一切正常。
JAXBContext jaxbContext = JAXBContext.newInstance(ServerInformation.class); // The jaxb.properties must be in the same package as "ServerInformation.java"
Marshaller marshaller = jaxbContext.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.setProperty(MarshallerProperties.MEDIA_TYPE, MediaType.APPLICATION_JSON);
marshaller.setProperty(MarshallerProperties.JSON_INCLUDE_ROOT, false);
我的问题是:有没有解决方案将此文件放在另一个包中?我正在使用Maven插件wadl2java来生成一些包和类,并且在每次Maven构建之后,所有包都被删除并重新创建。所以我每次都丢失这个文件...
我想在我的ressource包中没有jaxb.properties的情况下将MOXy设置为我的JAXB提供程序。
我在同一个项目中有一些其他包,我可以把这个文件放进去。
My question is: is there any solution to put this file in another package ? I am using a Maven plugin "wadl2java" to generate some packages and class, and after every Maven build, all packages are deleted and re-created. So I loose this file every time...I would like a solution to set MOXy as my JAXB provider without the "jaxb.properties" in my ressource package.I have some others packages in the same project, and I can put this file in.
有什么想法吗?
谢谢。
推荐答案
有几种方法可以将MOXy设置为JAXB Provider。
There are several ways how to set MOXy as JAXB Provider.
-
将系统属性JAXBContext.JAXB_CONTEXT_FACTORY设置为org.eclipse.persistence.jaxb.JAXBContextFactory
To set system property JAXBContext.JAXB_CONTEXT_FACTORY to org.eclipse.persistence.jaxb.JAXBContextFactory
- http://docs.oracle.com/javaee/7/api/javax/xml/bind/JAXBContext.html#JAXB_CONTEXT_FACTORY
使用org.eclipse.persistence.jaxb.JAXBContextFactory创建META-INF / services / javax.xml.bind.JAXBContext文件
To create META-INF/services/javax.xml.bind.JAXBContext file with org.eclipse.persistence.jaxb.JAXBContextFactory
- http://docs.oracle.com/cd/E24329_01/web.1211/e24964/data_types.htm#WSGET346
使用org.eclipse.persistence.jaxb.JAXBContextFactory
using org.eclipse.persistence.jaxb.JAXBContextFactory
- Can I replace jaxb.properties with code?
这篇关于将MOXy设置为JAXB Provider,而不在同一个包中使用属性文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!