0

I'm building an application using Ajax,jsp and Java. I meet the problem when I call Java reflection by Ajax call. This is the error:

Feb 22, 2014 11:39:13 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [optSim] in context with path [/Manager] threw     exception
java.lang.RuntimeException: No resource for it/Manager/Support

the code that thrown the exception is:

 public static Vector<Class> getClassesForPackage(Package pkg) {
    String pkgname = pkg.getName();

    Vector<Class> classes = new Vector<Class>();

    // Get a File object for the package
    File directory = null;
    String fullPath;
    String relPath = pkgname.replace('.', '/');
    System.out.println(System.getProperty("java.class.path"));
    // System.out.println("ClassDiscovery: Package: " + pkgname +
    // " becomes Path:" + relPath);

    System.out.println(System.getProperty("java.class.path"));

    URL resource = ClassLoader.getSystemClassLoader().getResource(relPath);

    // System.out.println("ClassDiscovery: Resource = " + resource);
    if (resource == null) {
        throw new RuntimeException("No resource for " + relPath);
    }
    ....

In input this method take a package name and it search the class in the selected package. The problem is that if I call the method by jar file without Ajax this run correctly, otherwise return an error.

I print javaclass path and it contains the directory src where are it/Manager/Support.

I thinks that the problem is in tomcat configuration.

Can anybody help me?

Thanks very Much

epascolo
  • 135
  • 2
  • 9
  • possible duplicate of [System.getProperty("java.class.path") does not show "WEB-INF/lib" and the including jars](http://stackoverflow.com/questions/4273039/system-getpropertyjava-class-path-does-not-show-web-inf-lib-and-the-includ) – Leo Feb 22 '14 at 11:21

1 Answers1

0

The solution are:

URL resource = Thread.currentThread().getContextClassLoader().getResource("path");

because when ajax call java code, i must select the threads ClassLoader otherwise java don't kwon what class loader take!

epascolo
  • 135
  • 2
  • 9