Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Iterate over classes in jar file

Tags:

java

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

like image 306
Roman Avatar asked Oct 29 '25 05:10

Roman


1 Answers

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();
  }
like image 64
Roman Avatar answered Oct 30 '25 23:10

Roman