Application Server Solutions for Microsoft IIS and ASP.NET
       solutions   products   partners   company   support   downloads         store
ServletExec Self-Help: FAQ
Back to Search >  Back to Search Results

Faq ID 395
Product ServletExec
Category Class Loading/Reloading
Question How can my code find out where classpath items reside?

.class files are looked for and loaded from various locations
as determined by the classloader. Here is an example of
ways you can see these locations for a particular item or package:

<%@ page import=", java.util.Enumeration" %>


<p>Finding the first location for a given class or resource (to see which one is being found and used by the classloader):</p>
 String itemToFind = "java/lang/String.class"; // setting itemToFind="" will tell you the first place the classloader looks for things.
 //example output: file:/C:/Program%20Files%20(x86)/Java/jdk1.6.0_16/jre/lib/rt.jar!/java/lang/String.class 

<p>Finding all locations for a given class or resource:</p>

  itemToFind = "META-INF/vfs-providers.xml";
  Enumeration<URL> locations = this.getClass().getClassLoader().getResources(itemToFind);
  while (locations.hasMoreElements())
    out.println("<li>" +((URL)locations.nextElement()).getPath()+ "</li>");


Note: These will be output in a different order than how the
classloader would actually find and load them.
See the javadocs for ClassLoader.getResources() which say
that the parent loader is searched first.


This technique can also be used to locate the JAR file that contains a particular package. For example:
itemToFind = "javax/servlet";

company media information terms of use privacy policy contact us