/**
* 创建接口
* 根据字符串类型的类的全路径(包含包名称),创建类的实例,最后强转为接口
*
* @param className = "com.quekua.iSpider.handle.impl.YixunHandleImpl";
* @param fileName = "E:/workspace/quekuawang/Developer/Shooter/iSpider/libs/handleImpl.jar";
* @return
* IHandle
* @exception/throws
*/
public static IHandle create(String className, String fileName){
IHandle iHandle = null;
try {
File file = new File(fileName);
ArrayList<URL> classPath = new ArrayList<URL>();
classPath.add(file.toURI().toURL());
//URL[] arrayUrl = new URL[0];
ClassLoader loader = new URLClassLoader(classPath.toArray(new URL[0]));
//Thread.currentThread().setContextClassLoader(loader);
Class<?> mainClass = Class.forName(className, true, loader);
iHandle = (IHandle)mainClass.newInstance();
} catch (Exception e) {
e.printStackTrace();
}
return iHandle;
}
* 创建接口
* 根据字符串类型的类的全路径(包含包名称),创建类的实例,最后强转为接口
*
* @param className = "com.quekua.iSpider.handle.impl.YixunHandleImpl";
* @param fileName = "E:/workspace/quekuawang/Developer/Shooter/iSpider/libs/handleImpl.jar";
* @return
* IHandle
* @exception/throws
*/
public static IHandle create(String className, String fileName){
IHandle iHandle = null;
try {
File file = new File(fileName);
ArrayList<URL> classPath = new ArrayList<URL>();
classPath.add(file.toURI().toURL());
//URL[] arrayUrl = new URL[0];
ClassLoader loader = new URLClassLoader(classPath.toArray(new URL[0]));
//Thread.currentThread().setContextClassLoader(loader);
Class<?> mainClass = Class.forName(className, true, loader);
iHandle = (IHandle)mainClass.newInstance();
} catch (Exception e) {
e.printStackTrace();
}
return iHandle;
}