有时这样处理更方便。比如说,加载某个包,执行main(String[] args),范例代码如下:
private static void proguard(final String proguardDir) { //直接加载lib,执行语句如下: //proguard.ProGuard.main(new String[] {CONFIG_FILE}); try { URL url1 = new URL("file:D:/lib/proguard.jar"); URLClassLoader classLoader = new URLClassLoader(new URL[] { url1 }, Thread.currentThread().getContextClassLoader()); Class<?> proguard = classLoader.loadClass("proguard.ProGuard"); Method mainMethod = proguard.getDeclaredMethod("main", String[].class); mainMethod.invoke(null, new Object[] {new String[] { CONFIG_FILE}}); classLoader.close(); } catch (Exception e) { e.printStackTrace(); } }