我将在这个问题中尽量做到描述性的,因为它很难解释。
开始吧。我有两个jar文件。一个(我自己的)和一个( Bukkit jar)。bukkit jar,我在"./Server/bukkit.jar“中找到了”./Server/bukkit.jar“,我正在尝试访问运行中的bukkit jar实例中的"org.bukkit.Bukkit.getServer()”方法,该实例是由我自己的jar中的进程构建器启动的。
所以,这里..。
我自己的Jar代码:
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..?
}
}发布于 2012-12-27 03:23:53
此方法将不适用于。您正在尝试引用加载在单独system process中的Java类-它是否是当前进程的子进程并不重要。从Java的角度来看,它是一个单独的Java虚拟机,两者之间没有Java特定的通信。
相反,您需要做的是:
execute (example here).
org.bukkit.craftbukkit.Main.main(new String [] {"your arguments here"}).
Fukkit.main(),executeorg.bukkit.craftbukkit.Main.main(new String [] {"your arguments here"}).Fukkit.main(),execute main,execute main method,execute main method,execute main,execute main,execute main method,execute main,execute main method,execute main,executeorg.bukkit.craftbukkit.Main.main(new String [] {"your arguments here"}).Fukkit.main(),execute,execute当我完成这个快速回答时,我现在才注意到您关于JAR可能正在更新的评论。当然,有一些在运行时重新加载JAR的高级方法,但我建议只要发生这样的更新,就可以简单地重新启动您的程序。
另外,Bukkit不是有一个插件架构(我假设我们说的是Minecraft Bukkit服务器)吗?也许你想绕个弯,这就是导致问题的原因?尝试检查Bukkit的API是否不支持做你想做的事情。
https://stackoverflow.com/questions/14044997
复制相似问题