Closed bravehorsie closed 5 years ago
version 2.4.0-b180830.0359 has different license - may or may not be an issue.
in any case ballot for 2.3.3 has already been started, see https://www.eclipse.org/lists/jakarta.ee-spec/msg00593.html for details
Hello, In our application we have upgraded to JAVA 11 .After intergrating the JAXB-API(2.3) ,JAXB-Runtime(2.3) and activation(1.1). I am still getting exception : Implementation of JAXB-API has not been found on module path or classpath.
org.glassfish.jaxb* artifacts we're never intended for usage in OSGi environment (this will very likely change rather sooner than later); if you need OSGi, then com.sun.xml.bind:jaxb-osgi is what one needs (it's being consumed by GlassFish - which is OSGi based, or latest eclipselink)
Solved it for me, thank you!
Still having the issue with following dependencies in the classpath running on JDK11 (oracle):
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>2.3.3</version>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>2.3.3</version>
</dependency>
javax.xml.bind.JAXBException: Implementation of JAXB-API has not been found on module path or classpath.
- with linked exception:
[java.lang.ClassNotFoundException: com.sun.xml.bind.v2.ContextFactory]
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:232)
at javax.xml.bind.ContextFinder.find(ContextFinder.java:375)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:691)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:632)
[...]
Caused by: java.lang.ClassNotFoundException: com.sun.xml.bind.v2.ContextFactory
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
at javax.xml.bind.ServiceLoaderUtil.nullSafeLoadClass(ServiceLoaderUtil.java:92)
at javax.xml.bind.ServiceLoaderUtil.safeLoadClass(ServiceLoaderUtil.java:125)
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:230)
... 90 more
What do you suggest ?
See my comment here, when current thread classloader is a PlatformClassLoader
, the JAXB runtime MUST be in added as a module in order to be available.
Here is my solution using JAXB 2.3.3 (on jdk8 to 16) to explicitely define the ContextFactory class:
/** JAXB implementation 2.3.0 provided in JMCS libraries */
private static final String JAXB_CONTEXT_FACTORY_IMPLEMENTATION = "com.sun.xml.bind.v2.ContextFactory";
static {
// Define the system property to define which JAXB implementation to use:
System.setProperty("javax.xml.bind.JAXBContextFactory", JAXB_CONTEXT_FACTORY_IMPLEMENTATION);
System.setProperty(JAXBContext.JAXB_CONTEXT_FACTORY, JAXB_CONTEXT_FACTORY_IMPLEMENTATION);
if (org.apache.commons.lang.SystemUtils.JAVA_VERSION_FLOAT >= 16.0f) {
// JDK16 support fix:
/*
ERROR [main] com.sun.xml.bind.v2.runtime.reflect.opt.Injector - null
java.security.PrivilegedActionException: null
Caused by: java.lang.NoSuchMethodException: sun.misc.Unsafe.defineClass(java.lang.String,[B,int,int,java.lang.ClassLoader,java.security.ProtectionDomain)
at java.base/java.lang.Class.getMethod(Class.java:2195)
at com.sun.xml.bind.v2.runtime.reflect.opt.Injector$3.run(Injector.java:170)
at com.sun.xml.bind.v2.runtime.reflect.opt.Injector$3.run(Injector.java:166)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:554)
*/
final String key = "com.sun.xml.bind.v2.bytecode.ClassTailor.noOptimize";
System.setProperty(key, "true");
logger.info("Fix JDK-16+ support: version = {} (set {} = true)",
org.apache.commons.lang.SystemUtils.JAVA_VERSION_FLOAT, key);
}
logger.info("JAXB ContextFactory: {}", System.getProperty(JAXBContext.JAXB_CONTEXT_FACTORY));
}
Jaxb api uses invalid default factory class which referes to JDK versions, which has included JAXB implementation. Since JDK 11 it is no longer valid. Default factory class should be
"com.sun.xml.bind.v2.ContextFactory"
without"internal"
so it takes jaxb-ri as default or should be excluded completely printing describing error message when no implementation is found.See javax.xml.bind.ContextFinder