Ruben Laguna’s blog

Netbeans & Woodstox: ClassCastException: JAXBContextImpl Cannot Be Cast to JAXBContext

Are you getting a ClassCastException in a Netbeans Platform Application, when you are you sure that the class can be casted? Then check This is most likely the result of the the classes being loaded by different classloaders. So JAXBContextImpl cannot be cast to JAXBContext because that JAXBContext is from Classloader “A” and @JAXBContextImpl @can only be cast to @JAXBContext @from Classloader “B”.

SEVERE [global]
java.lang.ClassCastException: com.sun.xml.bind.v2.runtime.JAXBContextImpl cannot be cast to javax.xml.bind.JAXBContext
        at javax.xml.bind.ContextFinder.newInstance(
        at javax.xml.bind.ContextFinder.find(
        at javax.xml.bind.JAXBContext.newInstance(
        at javax.xml.bind.JAXBContext.newInstance(
        at javax.xml.bind.JAXBContext.newInstance(
        at com.rubenlaguna.en4j.mainmodule.ImportEvernoteFile.actionPerformed(
        at org.openide.awt.AlwaysEnabledAction.actionPerformed(
        at javax.swing.AbstractButton.fireActionPerformed(
        at javax.swing.AbstractButton$Handler.actionPerformed(
        at javax.swing.DefaultButtonModel.fireActionPerformed(
        at javax.swing.DefaultButtonModel.setPressed(
        at javax.swing.AbstractButton.doClick(
        at java.awt.MenuItem.processActionEvent(
        at java.awt.MenuItem.processEvent(
        at java.awt.MenuComponent.dispatchEventImpl(
        at java.awt.MenuComponent.dispatchEvent(
        at java.awt.EventQueue.dispatchEvent(
        at org.netbeans.core.TimableEventQueue.dispatchEvent(
[catch] at java.awt.EventDispatchThread.pumpOneEventForFilters(
        at java.awt.EventDispatchThread.pumpEventsForFilter(
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(
        at java.awt.EventDispatchThread.pumpEvents(
        at java.awt.EventDispatchThread.pumpEvents(
BUILD SUCCESSFUL (total time: 28 minutes 5 seconds)

So this could happen for example if you have both woodstox in a Netbeans Library Wrapper module and you make you application dependent on ide11JAXB 2.1 Library

In my case I was able to solve by just removing JAXB 2.1 Library from the application.