In my java project i have a jar that i generated with some classes. I am able to instantiate the instance of the class that is in my jar:
Alert a = new Alert();
But wen i try to do this:
JAXBContext context = JAXBContext.newInstance(Alert.class);
I get run time exception like this:
java.lang.InternalError: Error occured while invoking reflection on target classes. Make sure all referenced classes are on classpath: interface javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter Exception: null
Any idea what could be the issue? Thank you
This happened to me as I had defined XmlAdapter
implementations that were in a different JAR and not on the classpath. When trying to create the JAXBContext, it needs these adapters used by the JAXB type. Now that I figured this out, the message makes more sense, but is still very cryptic. XmlJavaTypeAdapter
is the annotation interface and the code fails to call the value()
method of the annotation as it returns Class<? extends XmlAdapter>
, a class type which is not defined on the classpath.
If you look at the code that throws the exception, this is impossible:
public Class More ...getClassValue(Annotation a, String name) {
try {
return (Class)a.annotationType().getMethod(name).invoke(a);
} catch (IllegalAccessException e) {
// impossible
throw new IllegalAccessError(e.getMessage());
} catch (InvocationTargetException e) {
// impossible
throw new InternalError(e.getMessage());
} catch (NoSuchMethodException e) {
throw new NoSuchMethodError(e.getMessage());
}
}
Would be nice if the cause of the exception was not lost.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With