JAXBContext、jaxb.properties 和 moxy [英] JAXBContext, jaxb.properties and moxy

查看:46
本文介绍了JAXBContext、jaxb.properties 和 moxy的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

jaxb.properties 需要与您正在创建 JAXBContext 的域类位于同一包中.

我正在使用 Moxy 的 xml 驱动配置,因为我不想使用注释或 XJC 生成的对象.我有一个现有的域类,它们分布在多个包中.这是否意味着我需要在所有这些包中都存在 jaxb.properties 或者有更好的选择(也许编写我自己的一些可以从 jvm arg 或其他东西读取的接口的实现)?

解决方案

这是否意味着我需要所有的 jaxb.properties那些包?

如果您在类上创建 JAXBContext,那么您需要在传入的域类的至少一个包中包含一个 jaxb.properties 文件.在下面的示例中,您可以在 package1package2 中有一个 jaxb.properties 文件.

JAXBContext jc = JAXBContext.newInstance(package1.Foo.class, package2.Bar.class);

如果您要在包名称上创建 JAXBContext,那么您至少需要在其中一个包中包含 jaxb.properties 文件.请注意,包由:"分隔.

JAXBContext jc = JAXBContext.newInstance("package1:package2");


<块引用>

或者有更好的选择

我的偏好是使用带有 jaxb.properties 文件的标准 JAXB API 来将 MOXy 指定为 JAXB 提供程序.有些人更喜欢使用本机 MOXy API 来执行此操作:

JAXBContext jc = org.eclipse.persistence.jaxb.JAXBContextFactory.createContext(new Class[] {Foo.class, Bar.class}, null);


更多信息

The jaxb.properties needs to be in the same package as the domain classes you are creating the JAXBContext on.

I am using Moxy's xml driven configuration since I doesn't want to use annotations or XJC generated objects. I have an existing domain classes that are spread across multiple packages. Does this mean that i need to have the jaxb.properties present in all those packages or there is a better alternative (Maybe writing my own implementation of some interface that can read from a jvm arg or something)?

解决方案

Does this mean that i need to have the jaxb.properties present in all those packages?

If you are creating your JAXBContext on classes, then you need to have a jaxb.properties file in at least one of the packages of the domain classes passed in. In the example below you could have a jaxb.properties file in either package1 or package2.

JAXBContext jc = JAXBContext.newInstance(package1.Foo.class, package2.Bar.class);

If you are creating your JAXBContext on package names, then you need to have a jaxb.properties files in at least one of the packages. Note that packages are separated by a ':'.

JAXBContext jc = JAXBContext.newInstance("package1:package2");


or there is a better alternative

My preference is to use the standard JAXB APIs with a jaxb.properties file to specify MOXy as the JAXB provider. Some people prefer using the native MOXy APIs to do this:

JAXBContext jc = org.eclipse.persistence.jaxb.JAXBContextFactory.createContext(new Class[] {Foo.class, Bar.class}, null);


For More Information

这篇关于JAXBContext、jaxb.properties 和 moxy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆