File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Help me out with dynamic class loader Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Help me out with dynamic class loader" Watch "Help me out with dynamic class loader" New topic

Help me out with dynamic class loader

Calanthe Wei
Ranch Hand

Joined: Oct 27, 2001
Posts: 42
Hi, all
I have trouble with Class.forName() to load class dynamically. This is a coed used in dispatch service.
My code is like
Class c = Class.forName(methodList.get(myMethod));
methodList is an instance of class that maintain the list of key/value. for example myMethod (key) TestMethod(value)
Can anyone gibe me some hint what's the possible reason that it cannot find the dynamic class?
Thank you so much!

The error is:
java.lang.ClassNotFoundException: TestMethod
at org.apache.tomcat.loader.AdaptiveClassLoader.loadClass(
at java.lang.ClassLoader.loadClass(
at java.lang.ClassLoader.loadClassInternal(
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(
at pointclickweb.servlet.Servlet.service(
at javax.servlet.http.HttpServlet.service(
at org.apache.tomcat.core.ServletWrapper.doService(
at org.apache.tomcat.core.Handler.service(
at org.apache.tomcat.core.ServletWrapper.service(
at org.apache.tomcat.core.ContextManager.internalService(
at org.apache.tomcat.core.ContextManager.service(
at org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(
at org.apache.tomcat.service.TcpWorkerThread.runIt(
at org.apache.tomcat.util.ThreadPool$
bill williams
Ranch Hand

Joined: Jan 15, 2002
Posts: 94
try to find out what is the current directory for the class loader

Yet Another SCJP2
Murali Vemulapalli

Joined: Apr 07, 2002
Posts: 2
with ear file, war file approach there are different class loaders. For ex. If you deploy an application using ear file on an app server, then there 3 different class loaders constructed internally.
1. system class loader
2. EJB class loader
3. Web class loader
The hierarchy of these class loaders is as follows.
system class loader<-EJB class loader<-web class loader
"<-" inheritence
A<-B - B inherits from A.
NOTE. a class loader can only access classed loaded by parent or itself. It CANNOT access classes loaded by any of its children class loader.
answer to your specific question...
"Could it be that you are calling a class loaded by child"
I agree. Here's the link:
subject: Help me out with dynamic class loader
It's not a secret anymore!