Search code examples
javaplayframeworkjaxbsbtmoxy

Specifying Moxy runtime for Play project with model in dependency


I'm working on a Play Framework project (WebProject) where I am using a jaxb/Moxy model defined in a jar I am importing through SBT. This jar is created from another project (ModelProject) by adding a "jaxb.properties" file to the package containing the model classes: javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory

To get this working for the unit tests in the ModelProject I had to add the following line to the build.sbt file: resourceDirectory in Compile <<= baseDirectory { _ / "src" }

My question is: Is there a way that I can use the Moxy runtime when I create a JAXBContext in the WebProject, using a class from the ModelProject to bootstrap it? Ideally I'd like to specify this within the ModelProject as it will be used by other projects in the future.

Thanks.


Solution

  • Maybe not an ideal solution but I just decided to create a package in the WebProject containing a "MoxyBootstrapper" class and a jaxb.properties file containing the javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory line.

    I then pass this class in when creating a new instance of the JAXBContext.