问题
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:
- 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.
回答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