Question

Suppose I have a jar file named test.jar. I am assigned the task to list all jars that are packed in this test.jar.

The catch is that whoever packed this test.jar, packed it in away that it doesn't show-up jars in the output of the below command, rather it's just a list of .class files and package structures.

jar -tvf test.jar

Any pointer in that direction please..

Was it helpful?

Solution

If it is Linux, you can try the unzip command:

unzip -l your_jar_file.jar

From Java you can also list the jar file contents. It must be something like this:

ZipFile jarFile = new ZipFile( jarFilePath );
Enumeration<? extends ZipEntry> entries = jarFile.entries();
while( entries.hasMoreElements() ) {
    System.out.println( entries.nextElement().getName() );
}

OTHER TIPS

To do this from within java, instantiate a ZipFile using the filename. The ZipFile has a method, entries(), which returns an Enumerator over all of the ZipEntries in the ZipFile (members in the jar). You can iterate using the enumerator and ask each entry for its name. List just those entries whose names end in ".jar"

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top