This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one 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 The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Digester Revisited..." Watch "Digester Revisited..." New topic
Author

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:

webapps/myApp/com/mypackage

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: http://aspose.com/file-tools
 
subject: Digester Revisited...