While using JAXB in JBoss, I am getting below exception while executing the code:
JAXBContext jaxbContext = JAXBContext.newInstance( jaxbElement.getClass().getPackage().getName() );
Exception which i am getting is:
[java.lang.ClassNotFoundException: com.sun.xml.internal.bind.v2.ContextFactory from [Module "deployment.project.ear.subproject-jboss.jar:main" from Service Module Loader]]
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:156) [jboss-jaxb-api_2.2_spec-1.0.4.Final-redhat-3.jar:1.0.4.Final-redhat-3]
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:108) [jboss-jaxb-api_2.2_spec-1.0.4.Final-redhat-3.jar:1.0.4.Final-redhat-3]
at javax.xml.bind.ContextFinder.find(ContextFinder.java:258) [jboss-jaxb-api_2.2_spec-1.0.4.Final-redhat-3.jar:1.0.4.Final-redhat-3]
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:412) [jboss-jaxb-api_2.2_spec-1.0.4.Final-redhat-3.jar:1.0.4.Final-redhat-3]
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:375) [jboss-jaxb-api_2.2_spec-1.0.4.Final-redhat-3.jar:1.0.4.Final-redhat-3]
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:279) [jboss-jaxb-api_2.2_spec-1.0.4.Final-redhat-3.jar:1.0.4.Final-redhat-3]
It looks like JBoss JAXB module is loading instead of JDK and this is the reason of exception, however I am not sure how to solve this error?
Finally i solved it by changing default context factory to eclipse link context factory, but not sure why it does not worked with default one.
JAXBContext jaxbContext = JAXBContextFactory.createContext( clss.getPackage().getName() , clss.getClass().getClassLoader());
and by importing org.eclipse.persistence.jaxb.JAXBContextFactory
class.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments