package file import java.util.jar.JarEntry import java.util.jar.JarFile import org.junit.Test; class ReadJarFileTest01 { @Test void test001(){ String default_path = "D:/tools/struts-2.3.16/lib/commons-lang-2.4.jar"; URL[] urls = new URL[1] urls[0] = new URL("file:" + default_path) ClassLoader parentclassloader = Thread.currentThread().getContextClassLoader() //URLClassLoader classLoader = new URLClassLoader(urls, parentclassloader) URLClassLoader classLoader = new URLClassLoader(urls) Map<String,List<String>> classMethodMap = new LinkedHashMap<String,List<String>>() JarFile jarfile = new JarFile(default_path) for(JarEntry entry : jarfile.entries()){ def ename = entry.getName() if( ename.contains(".class") ){ List<String> methods = new ArrayList<String>() classMethodMap.put(ename.substring(ename.lastIndexOf("/"), ename.lastIndexOf(".")), methods) def wholeClassName = ename.replaceAll("/", ".") wholeClassName = wholeClassName.substring(0, wholeClassName.lastIndexOf(".")) //println wholeClassName if( wholeClassName.contains("ArrayUtils") ){ Class clazz = classLoader.loadClass(wholeClassName) println clazz.getPackage().getName() java.lang.reflect.Method[] methodArr = clazz.getMethods() println "=================" for( p in methodArr ){ println p } } } } } }