开发者

Iterate over classes in jar file

Anyone knows a 2-3 line solution for iterating over classes in some Jar file ?

( I开发者_如何学运维 have an instance of java.net.URL in my hand )

Thanks


Accessing zips and jars using Java Part 1

Accessing zips and jars using Java Part 2

Here is a code snippet from first article:

  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();
  }


jar -tf xyz.jar|grep class

Here's a solution. You can create an input stream from the URL instead of the file that the code uses.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜