12

In order to use Moxy as JAXB Implementation, one has to add a file called jaxb.properties in the folder with the domain classes of the application and include the following line

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

Is it possible to make moxy the default for the project ? In case I have many different folders with annotated domain classes in which folder should I put this file?

Edmondo
  • 19,559
  • 13
  • 62
  • 115

1 Answers1

17

Note: I'm the EclipseLink JAXB (MOXy) lead and a member of the JAXB (JSR-222) expert group.

MOXy is already the default JAXB implementation in WebLogic 12.1.1:

In other environments 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.
bdoughan
  • 147,609
  • 23
  • 300
  • 400
  • Does it need to be in a different jar? Am I not allowed to do that in my current project? This is very annoying...should I have to create a new jar only for the purpose? – Edmondo Nov 06 '12 at 16:07
  • 1
    @Edmondo1984 - It doesn't need to be in a separate jar. Note that once you put the `META-INF/services/javax.xml.bind.JAXBContext` on the class path MOXy will become the default JAXB implementation for all applications sharing that class path. – bdoughan Nov 06 '12 at 16:11
  • Thanks. I believe it would be useful to add that to the eclipse link page on the wiki – Edmondo Nov 06 '12 at 16:14
  • 2
    I have added a file inside META-INF/services named javax.xml.bindJAXBContext inside my project, and set the content of this file to org.eclipse.persistence.jaxb.JAXBContextFactory, but still I don't get moxy used – Edmondo Nov 06 '12 at 16:26
  • 2
    Make sure the file is called `javax.xml.bind.JAXBContext` and not `javax.xml.bindJAXBContext`. In your comment you are missing a `.` between `bind` and `JAXBContext`. I just retried these steps in Eclipse and got MOXy as the provider of the `JAXBContext`. – bdoughan Nov 06 '12 at 16:33
  • This is solved, however it does not solve the fact that it complains about a missing no arg constructor for an @XmlTransient element :) – Edmondo Nov 06 '12 at 16:42
  • @Edmondo1984 - Could you enter a bug for that issue you are seeing (https://bugs.eclipse.org/bugs/enter_bug.cgi?product=EclipseLink)? Also which version of EclipseLink are you using (current version is 2.4.1). – bdoughan Nov 06 '12 at 16:55
  • @BlaiseDoughan I am unable to update the broken link to MOXy as it not at least a 6 character change. http://www.eclipse.org/eclipselink/#moxy – rjdkolb Apr 21 '16 at 09:43