Does MOXy need anything special when using with schema-derived classes?

折月煮酒 提交于 2019-12-11 13:37:55

问题


I saw this question:

Using Moxy as JAXB Implementation and setting jaxb.properties with more than one POJO package

And wanted to ask the following:

Does MOXy need anything special when using with schema-derived classes? For instance, are jaxb.properties files required in each of the packages?


回答1:


The following applies to whether the classes were generated from an XML Schema, or were hand built POJOs.

Specifying MOXy as the JAXB Provider for an Individual JAXBContext

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");

The contents of the jaxb.properties must be:

javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory

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:

You could also leverage the META-INF/services mechanism to specify MOXy as the default JAXB provider:

  1. Create a JAR that contains a file called javax.xml.bind.JAXBContext in the directory META-INF/services
  2. The contents of the javax.xml.bind.JAXBContext file must be org.eclipse.persistence.jaxb.JAXBContextFactory
  3. Add that jar to your classpath.



回答2:


I don't has right to comment, so i give a answer here. Recently I choose MOXy in the project and meet the problem too. We use maven for build tool, if you use maven too, you can simply create diretory META-INF/services under the resources directory, and create a file named javax.xml.bind.JAXBContext under META-INF/services, then edit the file with contents org.eclipse.persistence.jaxb.JAXBContextFactory.



来源:https://stackoverflow.com/questions/26411849/does-moxy-need-anything-special-when-using-with-schema-derived-classes

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!