Maven XJC and wrong JAXB version issue

From Foochal

Jump to: navigation, search


This error sometimes arises when you run maven XJC plugin and then compile the generated classes

MarshalUtil.java:51: cannot find symbol
symbol  : variable JAXB_FRAGMENT
location: interface javax.xml.bind.Marshaller
    marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);

The error is due an incompatible version of Marshaller present in the classpath. There are two versions of Marshaller. One contains a constant , and the other one doesn't.

Somehow XJC generates code to be compiled with the first version of Marshaller, but at runtime the second version is found and it causes this error.

Maven group/artifact/version Marshaller.JAXB_FRAGMENT present?
javax.xml.bind/jaxb-api/2.0 yes
javax.xml/jaxb-api/2.0 yes

The solution is find all versions javax.xml.bind.Marshaller classes in your classpath and see whether or not it contains the JAXB_FRAGMENT constant. If yes, then good, if no then this jar is the culprit.


Personal tools