Code for listing classes present in a Jar file

package com.wordpress.narendrakadali.util;

import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;

public class ListAllClassesInJar

	 * @param args
	 * @throws IOException
	public static void main(String[] args) throws IOException
		List classNames = new ArrayList();
		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();
				if (name.endsWith(".class"))
					classNames.add(name.replace(".class", "").replace("/", "."));

			System.out.println("Please enter the jar filename as argument");


  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: