You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Ricardo Ramírez <rr...@itesm.mx> on 2005/07/31 10:58:26 UTC

Classloading and simpleClassForName

I am looking at the following method in the ClassUtils.java file:

    public static Class classForName(String type)
        throws ClassNotFoundException
    {
        if (type == null) throw new NullPointerException("type");
        try
        {
            // Try WebApp ClassLoader first
            return Class.forName(type,
                                 false, // do not initialize for faster startup
                                 Thread.currentThread().getContextClassLoader());
        }
        catch (ClassNotFoundException ignore)
        {
            // fallback: Try ClassLoader for ClassUtils (i.e. the myfaces.jar
lib)
            return Class.forName(type,
                                 false, // do not initialize for faster startup
                                 ClassUtils.class.getClassLoader());
        }
    }

I wonder if someone could explain me why it is done that way? (first the
current thread, then the classloader for classutil)

I am using Orion, somehow that doesn't work for me, I can initialize 1 web
application, however if I try to initialize a second one I get:
Class org.apache.myfaces.application.ActionListenerImpl is no javax.faces.event.ActionListener

After some debugging I checked and:

ClassLoader: [webapp1\classes, webapp1\lib\somejar] org.apache.myfaces.application.ActionListenerImpl

ClassLoader: [anotherapp2\classes, anotherpp2\lib\somejar] 
javax.faces.event.ActionListener

They are in different classloaders... that's why the "isAssignableFrom" method
returns false.

I don't know if this is a bug in orion server or in myfaces..... webapp1
and anotherapp2, both exist and are separate web modules, each with the myfaces
jars in the WEB-INF directory, if there is no special reason for loading
first the current thread then the classloader for ClassUtil I'll try chaning
the order.