3 Replies Latest reply on Apr 15, 2006 7:51 PM by aguizar

    Perplexing implementation of ProcessClassLoader.findClass

    reidmp

      Hi all,

      I'm trying to use jBPM 3.1 in an EJB project. Don't care about Hibernate functionality, just in-memory usage of jBPM from a session bean. I created an action and ran into a class loading exception that from past messages in this forum I can see isn't unusual. Alas, in my project using the UCL isn't an option (even if it were, I'm not a fan of the UCL). I was looking in ProcessClassLoader to see what I could do about the problem, code shown below:

       public Class findClass(String name) throws ClassNotFoundException {
       Class clazz = null;
       FileDefinition fileDefinition = processDefinition.getFileDefinition();
       if (fileDefinition!=null) {
       String fileName = "classes/" + name.replace( '.', '/' ) + ".class";
       byte[] classBytes = fileDefinition.getBytes(fileName);
       clazz = defineClass(name, classBytes, 0, classBytes.length);
       }
       if (clazz==null) {
       throw new ClassNotFoundException("class '"+name+"' could not be found by the process classloader");
       }
       return clazz;
       }
      


      Unless I'm missing something, jBPM is only capable of loading classes that exist in a "classes" directory off the current classpath? Isn't that kinda strange? Isn't a "classes" dir what should be ON the classpath, not a subdirectory of something else on the classpath?

      The above implementation seems like it would be easy to fix so that it would work for components that have an appropriate classpath (e.g. because they have a manifest-specified classpath). Allowing for prioritizing backward compatibility with whatever motivated the original code, couldn't we just do:

       clazz = (clazz == null) ? super.findClass(name) : clazz;
       if (clazz==null) {
       throw new ClassNotFoundException("class '"+name+"' could not be found by the process classloader");
       }
      


      Am I missing something?