To specify EclipseLink MOXy as the JAXB provider, you need to put jaxb.properties in one of the packages for your domain objects, that is, passed to JAXBContext to load. For example, if your JAXBContext is based on the following two classes:
- example.foo.Foo
- example.bar.Bar
example.foo.Foo
package example.foo;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import example.bar.Bar;
@XmlAccessorType(XmlAccessType.FIELD)
public class Foo {
private Bar bar;
}
example.bar.Bar
package example.bar;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import example.foo.Foo;
@XmlAccessorType(XmlAccessType.FIELD)
public class Bar {
private Foo foo;
}
Example /Foo/jaxb.properties
, MOXy- JAXB, jaxb.properties , Foo.
javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory
Demo
Foo Bar , JAXBContext , , JAXBContext, .
package example;
import javax.xml.bind.JAXBContext;
import example.foo.Foo;
import example.bar.Bar;
public class Demo {
public static void main(String[] args) throws Exception{
System.out.println(JAXBContext.newInstance(Foo.class).getClass());
System.out.println(JAXBContext.newInstance(Bar.class).getClass());
System.out.println(JAXBContext.newInstance(Foo.class, Bar.class).getClass());
}
}
:
class org.eclipse.persistence.jaxb.JAXBContext
class com.sun.xml.bind.v2.runtime.JAXBContextImpl
class org.eclipse.persistence.jaxb.JAXBContext