0

Using the Bukkit-API I'm currently trying to create a plugin which can compile java code of a given pastebin link at runtime and execute that code. Everything is working so far except for one thing: I'm getting a ClassNotFoundException when I'm trying to access one of the already loaded plugins. (I'm not getting an exception when I'm using Bukkit-API methods!) All plugin jars have been added to the classpath; it currently looks like this:

/home/cubepanel/test-network/jars/craftcubbit.jar:/home/cubepanel/test-network/servers/ProHub/plugins/MultiCubeHub.jar:/home/cubepanel/test-network/servers/ProHub/plugins/MultiCubeCore.jar:

The classes I tried to load dynamically:

ClassNotFoundException for MutliCube

import be.multicu.core.MultiCube;

public class Test{

    public void debug() {
        System.out.println(MultiCube.getInstance());
    }
}

Working

import org.bukkit.Bukkit;

public class Test{

    public void debug() {
        System.out.println(Bukkit.getClass().getName());
    }
}

Sourcecode of RuntimeCompiler.java: http://paste.multicu.be/axigofekip.avrasm (It's a bit long, thats why I used a pastebin link)

I also noticed that I'm getting an compilation error when I removed the classpath of MultiCube.jar which means that the classpath must be correct since the sourcecode can be compiled.

EDIT: I was able to fix it by adding MultiCube.class.getClassLoader() as an argument in the constructor of my URLClassLoader

Joba
  • 777
  • 7
  • 24
  • 1
    A ClassNotFoundException always means there is something wrong with your runtime classpath. Either you are missing a JAR, or the JAR(s) don't contain the class. – Stephen C Aug 15 '14 at 14:29
  • 1
    Incidentally, it is bad practice to post links to "pastebin" code. When the pastebin links expire, your Question will become meaningless. And I don't understand why you linked to two copies of the same code. – Stephen C Aug 15 '14 at 14:32
  • Thats my problem... there is definitly a jar at this location and there is also definitly the MultiCube class in it. – Joba Aug 15 '14 at 14:32
  • Well, we can't exactly look over your shoulder to see what mistake you made ... and there is not enough hard information in your Question to say any more than I've already said. – Stephen C Aug 15 '14 at 14:34
  • What information do you need? – Joba Aug 15 '14 at 15:07
  • For example, the `java` command that is being used to launch the application. – Stephen C Aug 15 '14 at 15:15
  • java -jar craftcubbit.jar – Joba Aug 15 '14 at 15:37
  • That explains it. The `-jar` option causes the `java` command to ignore the $CLASSPATH environment variable. Read the Oracle manual page for `java` on the web ... – Stephen C Aug 15 '14 at 16:15
  • If it ignores the classpath.. why can my plugin compile and execute the 2nd code? – Joba Aug 15 '14 at 21:15
  • Possibly because there is a ClassPath entry in the JAR's manifest. But don't just take my word for it. Go and read the documentation!!! (The reason that compilation does work is obvious, the `javac` command >>is<< using $CLASSPATH.) – Stephen C Aug 16 '14 at 00:09
  • That arguement confuses me a little. Why would it be able to access the server jar but not the jar which is actually compiling it and running it? The server jar (craftcubbit.jar) starts the plugin (MultiCubeCore.jar) but the plugin jar doesn't know where the craftcubbit jar is located. (Therefore it's not in the manifest file) This is the reason why I try to set the craftcubbit.jar and the MultiCubeCore.jar in the classpath on compilation, but only accessing methods from the craftcubbit.jar is working. – Joba Aug 16 '14 at 11:01
  • Please go and read the documentation. It is all in there! The plugin.jar doesn't need to know where the server jar is. The contents of the server jar are already available via the plugin classloader's parent classloader. – Stephen C Aug 16 '14 at 11:09
  • is the plugin you're hooking into also on the same server – hintss Sep 04 '14 at 07:26

0 Answers0