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

      

  • 相关阅读:
    (转载)关于一些对location认识的误区
    Python内置数据结构--列表
    Maven
    Python基础语法
    安装ipython和jupyter
    Python环境安装
    Java多线程
    SpringMVC集成springfox-swagger2自动生成接口文档
    SpringMVC拦截器
    SpringMVC异常处理器
  • 原文地址:https://www.cnblogs.com/juedui0769/p/3989581.html
Copyright © 2011-2022 走看看