zoukankan      html  css  js  c++  java
  • 加载jar文件输出class和method

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

      

  • 相关阅读:
    基本算法2
    基本算法
    读书笔记 《跟老齐学python》
    python杂记 20200207 离线安装 正则
    傻傻分不清之 Cookie、Session、Token、JWT 转载:https://juejin.im/post/5e055d9ef265da33997a42cc
    并发相关 杂记
    原根
    POJ2749 Building roads
    luogu P4735 最大异或和
    SP913 QTREE2
  • 原文地址:https://www.cnblogs.com/juedui0769/p/3989581.html
Copyright © 2011-2022 走看看