我正在尝试使用 MOXy 作为我的 JAXB 提供程序,以便将内容编码/解码为 XML/JSON。
我创建了“jaxb.properties”文件,内容为: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 构建之后,所有包都被删除并重新创建。所以我每次都丢失这个文件......
我想要一个解决方案,将 MOXy 设置为我的 JAXB 提供程序,而我的资源包中没有“jaxb.properties”。
我在同一个项目中有一些其他的包,我可以把这个文件放进去。
任何的想法 ?
谢谢。
最佳答案
有几种方法可以将 MOXy 设置为 JAXB Provider。
关于java - 将 MOXy 设置为 JAXB 提供者,在同一个包中没有属性文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28676613/