我注意到一个minecraft服务器加载了外部jar
文件。我想用它来创建一个小型游戏加载的集线器。我想通过调用一组jar
文件中的方法来加载它们。如果不直接执行它或修改类路径,这是否可行。我正在使用以下代码来启动和加载集线器:
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Window window = new Window();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
现在我将为一个文件夹中的jar文件数运行一个循环。我将这些存储在一个数组中。然后我希望按钮的操作从jar
文件
答案 0 :(得分:0)
Once you've configured your buildpath you import the class, create an instance of the class to use whatever method you're looking for. That should be it.
I think you can also do something like this (once it's added to your buildpath), not 100% sure on this one though.
ClassNameFromJarYouWant.MethodYouWant();
That'd be the easiest.
But if you really need to be able to add the JARs without modifying the classpath look up URLClassLoader. Here's a post I found that might help you.