井底之蛙

好记性不如烂笔头.菜鸟笔记.

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

 

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
					}
				}
			}
		}
	}
	
}

  

 

posted on 2014-09-23 23:17  井底之蛙丶  阅读(228)  评论(0编辑  收藏  举报