aspose file tools*
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
Author

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(AdaptiveClassLoader.java:524)
at java.lang.ClassLoader.loadClass(ClassLoader.java:253)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:313)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:120)
at pointclickweb.servlet.Servlet.service(Servlet.java:49)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:404)
at org.apache.tomcat.core.Handler.service(Handler.java:286)
at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:797)
at org.apache.tomcat.core.ContextManager.service(ContextManager.java:743)
at org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpConnectionHandler.java:210)
at org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:498)
at java.lang.Thread.run(Thread.java:484)
----Calanthe
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
Greenhorn

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"
 
 
subject: Help me out with dynamic class loader