001package ca.bc.webarts.tools; 002 003public class JWhich 004{ 005 006 /** 007 * Prints the absolute pathname of the class file 008 * containing the specified class name, as prescribed 009 * by the current classpath. 010 * 011 * @param className Name of the class. 012 */ 013 public static void which(String className) 014 { 015 016 if (!className.startsWith("/")) 017 { 018 className = "/" + className; 019 } 020 className = className.replace('.', '/'); 021 className = className + ".class"; 022 023 java.net.URL classUrl = new JWhich().getClass().getResource(className); 024 025 if (classUrl != null) 026 { 027 System.out.println("\nClass '" + right(className, className.length()- 1) + "' found in \n'" + classUrl.getFile() + "'"); 028 } 029 else 030 { 031 System.out.println("\nClass '" + right(className, className.length()- 1) + "' not found in \n'" + System.getProperty("java.class.path") + "'"); 032 } 033 } 034 035 036 /** 037 * Gives you the rightmost number of chars in a string. 038 **/ 039 public static String right(String value, int numChars) 040 { 041 String retVal = value; 042 if (value != null && value.length() >= numChars) 043 { 044 retVal = value.substring(value.length() - numChars); 045 } 046 return retVal; 047 } 048 049 050 /** 051 * Gives you the leftmost number of chars in a string. 052 **/ 053 public static String left(String value, int numChars) 054 { 055 String retVal = value; 056 if (value != null && value.length() >= numChars) 057 { 058 retVal = value.substring(0, numChars); 059 } 060 return retVal; 061 } 062 063 064 public static void main(String args[]) 065 { 066 if (args.length > 0) 067 { 068 JWhich.which(args[0]); 069 } 070 else 071 { 072 System.err.println("Usage: java ca.bc.webarts.tools.JWhich <classname>"); 073 } 074 } 075}