JarFile方法jar包获取

 private static void getClassInJarFile(Collection collection, Pattern pattern, String s)
    {
    	JarFile jarfile=null;
        try
        {
            jarfile = new JarFile(s);
            Enumeration enumeration = jarfile.entries();
            do
            {
                if(!enumeration.hasMoreElements())
                    break;
                String s1 = ((JarEntry)enumeration.nextElement()).getName().replace('\\', '/');
                Matcher matcher = pattern.matcher(s1);
                if(matcher.matches())
                    collection.add(s1);
            } while(true);
        }
        catch(Exception e) {
        	logger.info(e);
        }finally{
        	try {
        		if(jarfile!=null){
        			jarfile.close();
        		}
			} catch (IOException e1) {
				logger.info(e1);
			}
        }
    }
  

  

posted @ 2017-12-19 11:37  杯子茶壶  阅读(621)  评论(0)    收藏  举报