This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Servlets and the fly likes Digester Revisited... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Digester Revisited..." Watch "Digester Revisited..." New topic

Digester Revisited...

Jeffrey Hunter
Ranch Hand

Joined: Apr 16, 2004
Posts: 305
Hi again, Everyone. Sorry to keep hammering this board, but I'm in unexplored territory. As part of my continuing implementation of the Digester class, I'm now facing a problem to which the answer has been elusive, to say the least.

I'm using an Abstract Factory pattern to set up my web application. Basically, I have an abstract DaoFactory class which reads an XML file and instantiates the proper concrete DaoFactory (in this case, a MySqlDaoFactory instance).

Now, all is fine on my local machine however, when I run the app in the Tomcat context on the web, I get the inevitable <i>ClassNotFoundException</i>.

Consider the following a small example of my XML config file:

I have a DispatchServlet which calls DaoFactory.getInstance(). The getInstance() method parses the above XML file and instantiates the proper DaoFactory class. However, the class com.mypackage.MySqlDaoFactory cannot be found. My webapp directory structure is as follows:


All classes are in the above package. Is it something with the Digester? Why can it not find the class? Tomcat is loading myApp fine, so I assume all my classes are loaded. Any ideas? Thanks again for your continued attention!
Jeffrey Hunter
Ranch Hand

Joined: Apr 16, 2004
Posts: 305
UPDATE -- I've grabbed the ClassLoader from Digester using getClassLoader(), and it appears to be looking only at the Tomcat\common\* directory. Perhaps this is the issue. The Digester does not recognize my package, eventhough the Digester is being called from one of my classes. I'll now look at how to load my classes into the Digester. If you have any tips, let me know!
Jeffrey Hunter
Ranch Hand

Joined: Apr 16, 2004
Posts: 305
Haha, don't mind me, I enjoy having conversations with myself! Anyhow, I found the problem and I just wanted to close out this thread with a solution should anyone do a search and dig this up.

A call to digester.setUseContextClassLoader(true) will cause the Digester instance (digester) to load classes in the current context (in my case, WEB-INF/classes).
I agree. Here's the link:
subject: Digester Revisited...
Similar Threads
Implementing factory pattern with autowiring in spring
initialize DAO Factory
Help me understand this piece of code
Transaction Dermacation
Naming Exception in tomcat-3.3