i have an application running in jdk17 that tries to use jaxb, but is failing to load the actual jaxb-runtime.jar, it seems.
I have added jaxb-api.jar 2.3.1 and jaxb-runtime.jar 2.3.4 to the classpath
And i have this code
try (BufferedReader br = new BufferedReader(new java.io.InputStreamReader(getClass().getResourceAsStream("/META-INF/services/javax.xml.bind.JAXBContext")))) {
String cn = br.readLine();
Class c = Class.forName(cn);
System.out.println("Impl class: " + c.getName());
} catch (Exception e) {
e.printStackTrace();
}
context = JAXBContext.newInstance(getClass());
When run, i get
Impl class: com.sun.xml.bind.v2.ContextFactory
Caused by: java.lang.ClassNotFoundException: com.sun.xml.internal bind.v2.ContextFactory
at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:445)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:587)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
at javax.xml.bind.ServiceLoaderUtil.nullSafeLoadClass(ServiceLoaderUtil.java:122)
at javax.xml.bind.ServiceLoaderUtil.safeLoadClass(ServiceLoaderUtil.java:155)
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:276)
So this tells me that jaxb-runtime.jar is on the classpath, but for some reason, when the jaxb code goes to look for the correct Context Factory, it doesn't find the service lookup info, and just defaults to the default. (notice the .internal.)
If i add a jaxb.properties file and force it to pick my class, then it just CNFEs on com.sun.xml.bind.v2.ContextFactory
It's like there are two classloaders in play or something.
Anyone have any idea as to how to debug further?