2010-03-03 22 views
3

任何人都知道2-3行解決方案來迭代某些Jar文件中的類?迭代jar文件中的類

(我的java.net.URL的實例在我的手)

感謝

回答

4

Accessing zips and jars using Java Part 1

Accessing zips and jars using Java Part 2

下面是來自第一篇文章的代碼片段:

ZipFile zip = new ZipFile(fileName); 

    // Process the zip file. Close it when the block is exited. 

    try { 
    // Loop through the zip entries and print the name of each one. 

    for (Enumeration list = zip.entries(); list.hasMoreElements();) { 
     ZipEntry entry = (ZipEntry) list.nextElement(); 
     System.out.println(entry.getName()); 
    } 
    } 
    finally { 
    zip.close(); 
    } 
0

jar -tf xyz.jar | grep class

Here's a solution。您可以從URL中創建輸入流,而不是代碼使用的文件。