Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Listing classes in a jar file

How can I dynamically load a jar file and list classes which is in it?

like image 821
Hossein Margani Avatar asked Aug 07 '10 05:08

Hossein Margani


1 Answers

Here is code for listing classes in jar:

import java.io.IOException;
import java.util.Enumeration;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;

public class JarList {
    public static void main(String args[]) throws IOException {

        if (args.length > 0) {
            JarFile jarFile = new JarFile(args[0]);
            Enumeration allEntries = jarFile.entries();
            while (allEntries.hasMoreElements()) {
                JarEntry entry = (JarEntry) allEntries.nextElement();
                String name = entry.getName();
                System.out.println(name);
            }
        }
    }
}
like image 126
YoK Avatar answered Oct 04 '22 03:10

YoK