// // // Classpath - List all classes in Java Classpath // // Usage: java Classpath [classpath] // // This program will search recursively through the environment variable // CLASSPATH or a classpath entered on the command line. // // import java.io.*; import java.util.*; import java.util.jar.*; public class Classpath { static int depth; static String stringSet(String str, int n) throws IllegalArgumentException { if (n < 0) throw new IllegalArgumentException("n < 0"); String result = ""; for (int i=0; i entries = jarFile.entries(); entries.hasMoreElements();) { JarEntry entry = entries.nextElement(); String name = entry.getName(); if (name.endsWith(".class")) System.out.println(stringSet(" ",depth) + name); } // check jar files for a manifest classpath Manifest manifest = jarFile.getManifest(); if (manifest != null) { Attributes atts = manifest.getMainAttributes(); String jarClassPath = atts.getValue("Class-Path"); // if it has a classpath if (jarClassPath != null) { String[] jarPaths = jarClassPath.split(File.pathSeparator); for (int j=0; j