1 import java.util.zip.ZipFile;
2 import java.util.zip.ZipEntry;
4 String whichClass(String strClass)
6 String strBootCP = System.getProperty("sun.boot.class.path");
7 String strCP = System.getProperty("java.class.path");
10 strCP = strCP + File.pathSeparator + strBootCP;
13 return whichClassWithClassPath(strClass, strCP);
17 String whichClassWithClassPath(String strClass, String strCP)
19 String convertName(String str)
21 int nLength = str.length();
22 StringBuffer strRetVal = new StringBuffer(str);
23 for (int nCount = 0; nCount < nLength; nCount++)
25 if (strRetVal.charAt(nCount) == '.')
27 strRetVal.setCharAt(nCount, File.separatorChar);
31 strRetVal.append(".class");
32 return strRetVal.toString();
35 String convertToZipName(String str)
37 int nLength = str.length();
38 StringBuffer strRetVal = new StringBuffer(str);
39 for (int nCount = 0; nCount < nLength; nCount++)
41 if (strRetVal.charAt(nCount) == '.')
43 strRetVal.setCharAt(nCount, '/');
47 strRetVal.append(".class");
48 return strRetVal.toString();
50 boolean processEntry(String strFile, String strClass, String strZipName)
52 File file = new File(strFile);
54 if (file.isDirectory())
56 String strPath = strFile + File.separatorChar + strClass;
57 File classFile = new File(strPath);
58 return classFile.exists();
64 ZipFile zip = new ZipFile(file);
65 ZipEntry found = zip.getEntry(strZipName);
66 return (found != null);
70 System.out.println(ex.toString());
77 String strZipName = convertToZipName(strClass);
78 String strConvertedName = convertName(strClass);
85 print("Using classpath " + strCP + "\n\n");
86 StringTokenizer tokenizer = new StringTokenizer(strCP, File.pathSeparator);
87 while (tokenizer.hasMoreElements())
89 token = tokenizer.nextToken();
90 if (processEntry(token, strConvertedName, strZipName))
92 print("Class " + strClass + " is loaded from " + token);
96 print("No definition found for " + strClass);