3

I am trying to use MOXy as my JAXB provider in order to marshal/unmarshal content into XML/JSON.

I have created the "jaxb.properties" file with as content : javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactor

Everything works fine.

        JAXBContext jaxbContext = JAXBContext.newInstance(ServerInformation.class); // The jaxb.properties must be in the same package as "ServerInformation.java"
        Marshaller marshaller = jaxbContext.createMarshaller();

        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        marshaller.setProperty(MarshallerProperties.MEDIA_TYPE, MediaType.APPLICATION_JSON);
        marshaller.setProperty(MarshallerProperties.JSON_INCLUDE_ROOT, false);

My question is: is there any solution to put this file in another package ? I am using a Maven plugin "wadl2java" to generate some packages and class, and after every Maven build, all packages are deleted and re-created. So I loose this file every time... I would like a solution to set MOXy as my JAXB provider without the "jaxb.properties" in my ressource package. I have some others packages in the same project, and I can put this file in.

Any idea ?

Thanks you.

hiveship
  • 308
  • 2
  • 7
  • 21

1 Answers1

11

There are several ways how to set MOXy as JAXB Provider.

  1. To set system property JAXBContext.JAXB_CONTEXT_FACTORY to org.eclipse.persistence.jaxb.JAXBContextFactory

  2. To create META-INF/services/javax.xml.bind.JAXBContext file with org.eclipse.persistence.jaxb.JAXBContextFactory

  3. using org.eclipse.persistence.jaxb.JAXBContextFactory

Community
  • 1
  • 1
Martin Vojtek
  • 391
  • 3
  • 7