24 September 2010

Print classpath

import java.net.URL;
import java.net.URLClassLoader;

public class PrintClasspath {
       public static void main(String[] args) {

              //Get the System Classloader
              ClassLoader sysClassLoader = ClassLoader.getSystemClassLoader();

              //Get the URLs
              URL[] urls = ((URLClassLoader)sysClassLoader).getURLs();

              for(int i=0; i< urls.length; i++)
              {
                     System.out.println(urls[i].getFile());
              }

       }
}

2 comments:

  1. explain the getFile() method......

    ReplyDelete
  2. @niks2989 : http://download.oracle.com/javase/1.4.2/docs/api/java/net/URL.html#getFile() see this link you will get idea

    ReplyDelete