0

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

Tau
  • 33
  • 5
  • I cannot access hastebin from here, it's blocked. Have you added both `javax.xml.bind:jaxb-api` and `org.glassfish.jaxb:jaxb-runtime` and all their dependencies to the fat jar? Check: https://www.jesperdj.com/2018/09/30/jaxb-on-java-9-10-11-and-beyond – Polyana Fontes Mar 25 '20 at 12:53

1 Answers1

0

These dependencies are probably removed from the server and no longer available. Try searching on google and found newer versions of that dependencies. Also check compatibility between each other dependency.

PS: Check if you download Maven. I was also struggling and then found out that I don’t download Maven.

Explanation of your stack trace: Dependency cannot be found. Class that have the dependency cannot be founded. Error in classes that need the dependency.

Check if the Java version on server is same as on your computer. Try founding different versions of dependencies, because there can be problem in maven central repository. Check if you aren’t using native methods that works only on some operating systems.

Another problem is that you don’t uploaded some jar on the server that you have on you’re computer.

Check if you downloaded bukkit version that works with your JDK version.

  • Thanks for the answer, but here's the thing, I have tested it as a standalone executable jar and it worked. Indicating that the dependencies are packaged in the jar and are working. It breaks when it is running as a plugin under bukkit. https://hastebin.com/fuhamisumi.xml – Tau Mar 22 '20 at 05:49
  • Yes I looked on your test and output and it is working. Try and search if other plugins doesn’t mess with that yours. And check if the server you are running on have downloaded Maven. –  Mar 22 '20 at 05:59
  • Some of your classes are not loading properly. Try reinstalling Bukkit –  Mar 22 '20 at 06:01
  • Do you add all classes to build path properly? –  Mar 22 '20 at 06:02
  • This is my pom.xml https://hastebin.com/nebihuteha.xml And as i said it does work as a standalone app, just not when in bukkit, and yes, i'll try normal bukkit (i'm using tuinity[as it has a multi-threaded ChunkRegionManager]) And what do you mean install maven on the server, why would the minecraft server need maven exactly? and how would I go about doing it? My plugin is the only plugin on my test environment Update: no change when using stock bukkit. – Tau Mar 22 '20 at 08:00
  • Some servers need Maven to be downloaded to download dependencies properly. I do not know how it works on Linux&Windows, but on Mac I have to have it downloaded –  Mar 22 '20 at 08:19
  • Read this maybe help you https://www.spigotmc.org/threads/tutorial-how-to-use-maven.60122/ –  Mar 22 '20 at 08:28
  • Oh? I've not seen that used before to my knowledge, I've always just used Maven to package a fat jar and manage depends, If I'm understanding you correctly you're saying you can install maven on the server to download depends without them being in a fat jar? – Tau Mar 22 '20 at 08:38
  • Yes, that is the main thing about Maven –  Mar 22 '20 at 08:40
  • Something about maven and how it works: https://www.tutorialspoint.com/maven/maven_repositories.htm –  Mar 22 '20 at 08:41
  • Oh, I'm aware of how maven works in that respect, I think we have an misunderstanding here, I know what maven is and how it can be used, I thought you where saying you needed to install maven on the minecraft-bukkit server itself, That I think is where we misunderstood one another. – Tau Mar 22 '20 at 09:43
  • The only thing that can cause the proble is incompatible java version installed on server. –  Mar 22 '20 at 09:52
  • My testing server is on my machine and I'm using the same JDK for both the server and maven running java version 12.02, I updated to Java 13 on both to see if anything was different, it was not. – Tau Mar 22 '20 at 10:53
  • Try contacting bukkit devs. This situation is very rare. –  Mar 22 '20 at 11:08