Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help me out with dynamic class loader

 
Calanthe Wei
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try to find out what is the current directory for the class loader
 
Murali Vemulapalli
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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"
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic