📜  java 在运行时加载 jar - Java 代码示例

📅  最后修改于: 2022-03-11 14:52:29.484000             🧑  作者: Mango

代码示例3
URLClassLoader child = new URLClassLoader(
        new URL[] {myJar.toURI().toURL()},
        this.getClass().getClassLoader()
);
Class classToLoad = Class.forName("com.MyClass", true, child);
Method method = classToLoad.getDeclaredMethod("myMethod");
Object instance = classToLoad.newInstance();
Object result = method.invoke(instance);