开发者

Iterate over classes in jar file

开发者 https://www.devze.com 2022-12-21 15:57 出处:网络
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 )

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

精彩评论

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

关注公众号