问题描述
jaxb.properties
需要在 与域类相同的包 中创建JAXBContext上。
The jaxb.properties
needs to be in the same package as the domain classes you are creating the JAXBContext on.
我正在使用Moxy的xml驱动配置,因为我不想使用注释或XJC生成的对象。我有一个分布在多个包中的现有域类。这是否意味着我需要在所有这些包中存在 jaxb.properties
或者有更好的替代方法(也许编写我自己的某些接口的实现,可以从jvm arg或东西)?
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)?
推荐答案
如果您要创建 JAXBContext
在类上,然后你需要在传入的域类的至少一个包中有一个 jaxb.properties
文件。在下面的例子中你可以有一个 jaxb.properties
文件在 package1
或 package2
。
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);
如果要在包装上创建 JAXBContext
名称,然后你需要在至少一个包中有一个 jaxb.properties
文件。请注意,包由':'分隔。
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");
我的首选是使用标准的JAXB API和 jaxb.properties
file指定MOXy作为JAXB提供程序。有些人更喜欢使用本机MOXy API来执行此操作:
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);
更多信息
- http://blog.bdoughan.com/2011/05/specifying-eclipselink-moxy-as-your.html
这篇关于JAXBContext,jaxb.properties和moxy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!