Hi I'm currently working on updating one of my Bukkit plugins to java 12 (from 8) Every other library went off without a hitch (short of updating some of them) However as most of you know JAXB was removed in J11 completely, thus I'm using these dependencies
in my fat jar. However, after compiling then running it, I get this runtime error:
[13:34:48 WARN]: javax.xml.bind.DataBindingException: javax.xml.bind.JAXBException: Implementation of JAXB-API has not been found on module path or classpath.
[13:34:48 WARN]: - with linked exception:
[13:34:48 WARN]: [java.lang.ClassNotFoundException: com.sun.xml.internal.bind.v2.ContextFactory]
[13:34:48 WARN]: at javax.xml.bind.JAXB._marshal(JAXB.java:559)
[13:34:48 WARN]: at javax.xml.bind.JAXB.marshal(JAXB.java:317)
[13:34:48 WARN]: at me.taucu.server.minevictus.minesuiteus.Minesuiteus.marshalFile(Minesuiteus.java:702)
[13:34:48 WARN]: at me.taucu.server.minevictus.minesuiteus.Minesuiteus.testXml(Minesuiteus.java:195)
[13:34:48 WARN]: at me.taucu.server.minevictus.minesuiteus.Minesuiteus.onEnable(Minesuiteus.java:148)
[13:34:48 WARN]: at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:263)
[13:34:48 WARN]: at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:337)
[13:34:48 WARN]: at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:435)
[13:34:48 WARN]: at org.bukkit.craftbukkit.v1_15_R1.CraftServer.enablePlugin(CraftServer.java:470)
[13:34:48 WARN]: at org.bukkit.craftbukkit.v1_15_R1.CraftServer.enablePlugins(CraftServer.java:384)
[13:34:48 WARN]: at net.minecraft.server.v1_15_R1.MinecraftServer.a(MinecraftServer.java:482)
[13:34:48 WARN]: at net.minecraft.server.v1_15_R1.DedicatedServer.init(DedicatedServer.java:299)
[13:34:48 WARN]: at net.minecraft.server.v1_15_R1.MinecraftServer.run(MinecraftServer.java:885)
[13:34:48 WARN]: at java.base/java.lang.Thread.run(Thread.java:830)
[13:34:48 WARN]: Caused by: javax.xml.bind.JAXBException: Implementation of JAXB-API has not been found on module path or classpath.
[13:34:48 WARN]: - with linked exception:
[13:34:48 WARN]: [java.lang.ClassNotFoundException: com.sun.xml.internal.bind.v2.ContextFactory]
[13:34:48 WARN]: at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:232)
[13:34:48 WARN]: at javax.xml.bind.ContextFinder.find(ContextFinder.java:375)
[13:34:48 WARN]: at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:691)
[13:34:48 WARN]: at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:632)
[13:34:48 WARN]: at javax.xml.bind.JAXB$Cache.<init>(JAXB.java:97)
[13:34:48 WARN]: at javax.xml.bind.JAXB.getContext(JAXB.java:124)
[13:34:48 WARN]: at javax.xml.bind.JAXB._marshal(JAXB.java:548)
[13:34:48 WARN]: ... 13 more
[13:34:48 WARN]: Caused by: java.lang.ClassNotFoundException: com.sun.xml.internal.bind.v2.ContextFactory
[13:34:48 WARN]: at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:602)
[13:34:48 WARN]: at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
[13:34:48 WARN]: at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
[13:34:48 WARN]: at javax.xml.bind.ServiceLoaderUtil.nullSafeLoadClass(ServiceLoaderUtil.java:92)
[13:34:48 WARN]: at javax.xml.bind.ServiceLoaderUtil.safeLoadClass(ServiceLoaderUtil.java:125)
[13:34:48 WARN]: at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:230)
[13:34:48 WARN]: ... 19 more
[13:34:48 ERROR]: [Minesuiteus] Exception while testing XML marshalling, cannot continue
[13:34:48 INFO]: [Minesuiteus] Disabling Minesuiteus v0.3.7
[13:34:48 INFO]: [Minesuiteus] Disabling Modules...
[13:34:48 INFO]: [Minesuiteus] Disabling Utilities...
[13:34:48 INFO]: [Minesuiteus] Shutting down executer services...
And this is the code:
public static void marshalFile(Object obj, File clazzFileLocation) {
JAXB.marshal(obj, clazzFileLocation);//Trying simple method in-case I did something wrong
/*FileOutputStream out = null;
try {
out = new FileOutputStream(clazzFileLocation);
JAXBContext context = JAXBContext.newInstance(obj.getClass());
Marshaller m = context.createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
m.marshal(obj, out);
} catch (Throwable e) {
e.printStackTrace();
} finally {
if (out != null) {
try {
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}*/
}
The unmarshal uses much of the same simple JAXB#unmarshal(file, clazztype) method
Yes I have tried relocating the shaded libs to com.sun.xml.internal.bind... But to no luck, and yes I have checked that they're actually there.
I know that bukkit uses a non-system classloader to load plugins (which makes sense) But I think this is what is causing the issue.
I have ran the plugin as a standalone test and it WORKED, so the only variable here seems to be Bukkit and how it is loading the lib. I don't have problems with other libs in this manner, this has been the first.
My standalone test
public static void main(String[] args) throws IOException, ClassNotFoundException {
Console console = System.console();
Logger log = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME);
if (console == null && ClassLoader.getSystemClassLoader() == Main.class.getClassLoader()) {
PrintStream o = new PrintStream(new File("Minesuiteus-Headless.log"));
System.setOut(o);
System.setErr(o);
log.info("Running in headless mode");
log.info("### LOG START ###");
} else {
log.info("### START ###");
}
System.out.println();
log.info("Testing XML");
JAXB.marshal(new TestXML(), new File("./test.xml"));
TestXML t = JAXB.unmarshal(new File("./test.xml"), TestXML.class);
if (t == null) {
System.out.println("Test returned null, not working");
} else {
System.out.println("Test worked!");
}
log.info("Finished.");
}
Any suggestions?
Regards Tau