1 Reply Latest reply on Jan 9, 2007 3:09 PM by Smith Aron

    URLClassLoader loadClass() throws NoClassDefFoundError for S

    Martha Mitran Newbie

      I am trying to use URLClassLoader class tor retrieve information about a class in the local file system, using the version 4.0.5 of the JBoss application server.
      I have a business function in a session bean class in which i do this:

       String classPathString = path;
       File classPath = new File(classPathString);
       File[] files = classPath.listFiles();
      
       try {
       URLClassLoader classLoader;
       Thread.currentThread().setContextClassLoader(
       classLoader = new URLClassLoader(
       new URL[] {files[0].toURL()}
       )
       );
       Class c = classLoader.loadClass("classbro.ejb.JClassBroBean");
       return c.getName();
       } catch(ClassNotFoundException e) {
       return "Class not found.";
       } catch(MalformedURLException e) {
       return "Malformed URL.";
       }
      

      The call of loadClass throws a NoClassDefFoundError for javax/ejb/SessionBean, which I cannot understand. The class which I put there exists and it is found, because I tested this. How could I fix this problem?

      Thanks.