Search code examples
javajaxbjava-11rcp

JAXBContext#newInstance in java11 RCP application


I am migrating an existing Eclipse RCP application from Java8 to Java11. Therefore, the JAXB plugin needs to be added manually now. If anyone is looking for a good example, I found this one: https://github.com/vogellacompany/eclipsercp-jaxb-java11

There, the JAXBContext is instantiated like so:

JAXBContext.newInstance(Bookstore.class.getPackageName(), Bookstore.class.getClassLoader());

Is there any way to get the factory working by only passing the class? Like so:

JAXBContext.newInstance(Bookstore.class);

In the second case we get this exception:

java.lang.ClassNotFoundException: org.eclipse.persistence.jaxb.JAXBContextFactory

Solution

  • The moxy implementation offers an explicit factory to create the JAXBcontext: org.eclipse.persistence.jaxb.JAXBContextFactory#createContext