Java如何在运行时动态加载JAR文件呢?
下文笔者讲述Java运行时--动态加载JAR文件的方法及示例分享,如下所示
动态加载JAR文件的方法
使用URLClassLoader即可实现动态加载JAR文件例:URLClassLoader动态加载JAR文件
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);
版权声明
本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。