0

I am trying to scan my webapplication classpath for all classes which implimenting certain interface.

My current application is working fine in stand alone version but failing in the web enviornment.

this is the portion of my code

public String[] getClassPathRoots() {
        String classPath;
          classPath = System.getProperty("java.class.path");
        }
        String[] pathElements = classPath.split(File.pathSeparator);
        return pathElements;
    }

i am not sure how to use java.class.path in my application so as i should be able to get the classpath root.

Umesh Awasthi
  • 23,407
  • 37
  • 132
  • 204
  • As per Servlet specification, all classes from classpath should be in `your-webapp/WEB-INF/classes` and `your-webapp/WEB-INF/lib` folders - or do you need classpath of web application container as well? – Yuriy Nakonechnyy May 29 '12 at 15:13
  • Try the answers to this question: http://stackoverflow.com/questions/1456930/how-do-i-read-all-classes-from-a-java-package-in-the-classpath – davidfrancis May 29 '12 at 15:26

1 Answers1

5

That property is set to the classpath that the JVM used at launch time. But a typical web container constructs the classpath (i.e. classloader hierarchy) for each webapp dynamically, and doesn't update the property to reflect this. (And it can't really, given that a web container may run multiple webapps, and each one will have a different class loader hierarchy. How are you going to represent that in the JVM's global System properties object?)

In short, you will need to find another way.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216