使用模式派生类时,MOXy是否需要任何特殊功能? [英] Does MOXy need anything special when using with schema-derived classes?
问题描述
我看到了这个问题:
使用Moxy作为JAXB实现并使用多个POJO包设置jaxb.properties
并且想要问以下内容:
在使用模式派生类时,MOXy是否需要任何特殊功能?例如,每个包中都需要 jaxb.properties
文件吗?
Does MOXy need anything special when using with schema-derived classes? For instance, are jaxb.properties
files required in each of the packages?
推荐答案
以下内容适用于是从XML Schema生成类,还是手工构建的POJO。
The following applies to whether the classes were generated from an XML Schema, or were hand built POJOs.
在内容路径上创建 JAXBContext
时(一个或更多包名称)使用 JAXB(JSR-222) 提供商(例如 MOXy ),而非默认您需要在其中一个软件包中包含一个 jaxb.properties
文件及相应的条目。例如,根据下面的代码, jaxb.properties
文件可以放在 com.example.pkg1
包或 org.example.pk2
package,或两者兼而有。
When creating a JAXBContext
on a content path (one or more package names) using a JAXB (JSR-222) provider (such as MOXy) other than the default you need to include a jaxb.properties
file with the appropriate entry in one of the packages. For example given the code below the jaxb.properties
file could be placed in either com.example.pkg1
package or org.example.pk2
package, or both.
JAXBContext jc = JAXBContext.newInstance("com.example.pkg1:org.example.pkg2");
jaxb.properties
的内容必须be:
javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory
将MOXy指定为所有JAXBContexts的默认JAXB提供程序
或者您可以配置您的环境,以便MOXy是默认的JAXB提供程序,以便不需要 jaxb.properties
文件。这可以通过以下方式完成:
Specifying MOXy as the Default JAXB Provider for all JAXBContexts
Alternatively you can configure your environment so that MOXy is the default JAXB provider so that the jaxb.properties
file isn't necessary. This is done as follows:
您还可以利用 META-INF / services
机制将MOXy指定为默认JAXB提供程序:
You could also leverage the META-INF/services
mechanism to specify MOXy as the default JAXB provider:
- 创建一个包含名为
javax.xml.bind.JAXBContext $的文件的JAR c $ c>目录
META-INF / services
-
javax.xml的内容。 bind.JAXBContext
文件必须是org.eclipse.persistence.jaxb.JAXBContextFactory
- 将该jar添加到你的类路径。
- Create a JAR that contains a file called
javax.xml.bind.JAXBContext
in the directoryMETA-INF/services
- The contents of the
javax.xml.bind.JAXBContext
file must beorg.eclipse.persistence.jaxb.JAXBContextFactory
- Add that jar to your classpath.
这篇关于使用模式派生类时,MOXy是否需要任何特殊功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!