URL url1 = new URL("file:D:/workspace/spider/plugin/plugin_fat.jar");
//加载类
URLClassLoader loader = new URLClassLoader(new URL[] { url1 }, Thread.currentThread().getContextClassLoader());
Class<?> cls = loader.loadClass("com.test.plugins.impl.LaserPrint");
//创建实例
IPrint print = (IPrint) cls.newInstance();
//调用
System.out.println(print.print("test"));
package com.test.plugins.impl;
import com.test.plugins.IPrint;
public class LaserPrint implements IPrint
{
@Override
public String print(String param)
{
String result = "log time: " + System.currentTimeMillis() + param;
return result;
}
}
package com.test.plugins;
public interface IPrint
{
String print(String param);
}