I’m going to attempt to be as descriptive as possible in this question, because it’s difficult to explain..
Here goes. I have two jar files. One (My own), and one (The Bukkit jar). the bukkit jar, i slovated in “./Server/bukkit.jar” I’m tring to access the method “org.bukkit.Bukkit.getServer()” inside a running instance of the bukkit jar started with a processbuilder in my own jar..
So, Here..
My Own Jar’s Code:
public class Fukkit {
public static void main(String[] args){
ProcessBuilder pb = new ProcessBuilder("java", "-cp", "bukkit.jar", "org.bukkit.craftbukkit.Main");
pb.directory(new File(new File(".").getPath() + File.separator + "Server"));
try {
pb.start();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//I now want to access that instance of bukkit.jar, and use the method
org.bukkit.Bukkit.getServer();
//From inside the jar..
//I cannot add it as a library, because the jar may be swapped out
//for another more updated version of bukkit.jar..
//But that method will always be present. Can someone help me out..?
}
}
This method will not work. You’re trying to reference Java classes loaded in a separate system process – it doesn’t matter whether it’s a child of your current process or not. From the Java point of view, it’s a separate Java Virtual Machine, with no Java-specific communication between the two.
What you need to do instead is:
Fukkit.main(), executeorg.bukkit.craftbukkit.Main.main(new String [] {"your arguments here"}).org.bukkit.Bukkit.getServer()and other methods.
When finishing this quick answer I’ve only now noticed your remark about the JAR being possibly updated. Well, there are some advanced methods of reloading JARs at runtime, but I would suggest to simply restart your program whenever such an update occurs.
Also, doesn’t Bukkit have a plugin architecture (I’m assuming we’re talking about the Minecraft Bukkit server)? Perhaps you’re trying to do it the roundabout way, and that’s causing the problem? Try to check whether doing what you want isn’t supported by Bukkit’s API.