import java.net.URL;
import java.security.CodeSource;

/**
 * Find out where a class on the classpath will be loaded from.
 * Fully qualified classname goes on the command line.
 */
public class Where
   {
   /**
    * main
    * @param args name of fully qualified class to find, using dots, but no dot class.
    * e.g. java.exe Where javax.mail.internet.MimeMessage
     */
   public static void main ( String[] args )
      {
      try
         {
         String qualifiedClassName = args[0];
         Class qc = Class.forName( qualifiedClassName );
         CodeSource source = qc.getProtectionDomain().getCodeSource();
         if ( source != null )
            {
            URL location = source.getLocation();
            out.println ( qualifiedClassName + " : " + location );
            }
         else
            {
            out.println ( qualifiedClassName + " : " + "unknown source, likely rt.jar" );
            }
         }
      catch ( Exception e )
         {
         err.println( "Unable to locate class on command line." );
         e.printStackTrace();
         }
      }
   }