java class using jaxb api failing in jira with : Provider com.sun.xml.bind.v2.ContextFactory not found

后端 未结 3 1070
北海茫月
北海茫月 2020-12-11 06:58

I am writing a plugin for Jira which involves parsing of XML documents. I am using JAXB to do so (XML to pojos and vice versa) So have a class which generates XML from pojos

3条回答
  •  遥遥无期
    2020-12-11 07:27

    Finally I was able find out the reason.

    There are many ClassLoaders involved while loading the plugins in JIRA (Felix). which will not delegate to 'bootstrap' ClassLoader. And hence the problem.

    To know which ClassLoader loaded the JAXBContext class, use JAXBContext.class.getClassLoader() which will print some Felix ClassLoader.

    It loaded the class from jaxb-api.jar instead of relying on rt.jar but they implemented the classes slightly different. rt.jar version uses com.sun.xml.bind.internal.v2.ContextFactory where jaxb-api version uses com.sun.xml.bind.v2.ContextFactory.

    I am able to solve the issue using overlaoded method of JAXB which will take another parameter as ClassLoader.

    It took quite some time. But, I am surprised by the inner details & my ignorance

提交回复
热议问题