Tech and Academic things for Chianshin

Thursday, April 09, 2009

classpath : Java Glossary

classpath : Java Glossary: "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();
System.out.println ( qualifiedClassName + ' : ' + location );
}
else
{
System.out.println ( qualifiedClassName + ' : ' + 'unknown source, likely rt.jar' );
}
}
catch ( Exception e )
{
System.err.println( 'Unable to locate class on command line.' );
e.printStackTrace();
}
}
}"

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]



<< Home