public class UrlClassLoad {
/**
* 获取一个jar加载器。
* @param file : jar的路径
* @return
*/
public static URLClassLoader getJarLoad(String file) {
try {
URL url = new URL("file:" + file);
URLClassLoader loader = new URLClassLoader(new URL[] { url });
return loader;
} catch (MalformedURLException e) {
e.printStackTrace();
}
return null;
}
/**
* 分析类中的函数
* @param clazzName :类的完整路径
*/
public static void analysisClazz(String jarFile){
URLClassLoader urlClassLoader = getJarLoad(jarFile);
try {
Class<?> clazz = urlClassLoader.loadClass("com.swimap.lmt.po.Dept");
Object entity = clazz.newInstance();
Method method = clazz.getMethod("setDeptid", int.class);
Method method1 = clazz.getMethod("getDeptid", null);
method.invoke(entity, 110);
Object obj =method1.invoke(entity, null);
System.out.println(obj);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
analysisClazz("D:\\workbentchformyeclise\\LMT\\Dept.jar");
}
}
/**
* 获取一个jar加载器。
* @param file : jar的路径
* @return
*/
public static URLClassLoader getJarLoad(String file) {
try {
URL url = new URL("file:" + file);
URLClassLoader loader = new URLClassLoader(new URL[] { url });
return loader;
} catch (MalformedURLException e) {
e.printStackTrace();
}
return null;
}
/**
* 分析类中的函数
* @param clazzName :类的完整路径
*/
public static void analysisClazz(String jarFile){
URLClassLoader urlClassLoader = getJarLoad(jarFile);
try {
Class<?> clazz = urlClassLoader.loadClass("com.swimap.lmt.po.Dept");
Object entity = clazz.newInstance();
Method method = clazz.getMethod("setDeptid", int.class);
Method method1 = clazz.getMethod("getDeptid", null);
method.invoke(entity, 110);
Object obj =method1.invoke(entity, null);
System.out.println(obj);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
analysisClazz("D:\\workbentchformyeclise\\LMT\\Dept.jar");
}
}