public class TestMain {
public static void main(String[] args) {
try {
//第一种 配置成文件格式
File file = new File("D:\\jars\\test.txt");
BufferedReader in = new BufferedReader(new FileReader(file));
String s = new String();
while ((s = in.readLine()) != null) {
URL url = new URL(s);
s = null;
URLClassLoader myClassLoader = new URLClassLoader(new URL[] { url }, Thread.currentThread()
.getContextClassLoader());
Class<?> myClass = (Class<?>) myClassLoader.loadClass("com.java.jars.xxxHandler");
InterfaceAction action = (InterfaceAction) myClass.newInstance();
String str = action.action();
System.out.println(str);
//第二种从指定路径加载jar并执行某个方法
URL url1 = new URL("file:E:/jars/test.jar");
URLClassLoader myClassLoader1 = new URLClassLoader(new URL[] { url1 }, Thread.currentThread()
.getContextClassLoader());
Class<?> myClass1 = myClassLoader1.loadClass("com.java.jars.xxxHandler");
InterfaceAction action1 = (InterfaceAction) myClass1.newInstance();
String str1 = action1.action();
System.out.println(str1);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
动态加载java文件(记录)
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 1.搜索powershell,右键以管理员身份运行(Windows PowerShell) 2.执行:set-Ex...
- 有这样的一个需求,我在上传文件的时候,上传阶段耗时较长,所以利用加载动画作为友好提示用户等待。 该组件的使用方式如...
- 如题,发现苹果自带的浏览器safari或xcode里面用代码webview加载一个文件下载地址,如http://f...