aspose file tools*
The moose likes Tomcat and the fly likes Tomcat 5.5 not loading resources in WEB-INF/classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Tomcat 5.5 not loading resources in WEB-INF/classes" Watch "Tomcat 5.5 not loading resources in WEB-INF/classes" New topic
Author

Tomcat 5.5 not loading resources in WEB-INF/classes

Bob Peterson
Ranch Hand

Joined: Jul 30, 2004
Posts: 47
By resources I mean log4j.xml and an xml config file we use to configure our DB connections/DataSources. I'm just trying to get a bare-bones web app up and running to test our main software product (a jar) in a web environment. I'm just doing the simple testing in a jsp. It's finding our main jar and other dependent jars in web-inf/lib. The simple jsp is working, although I haven't tried a servlet or any other class yet to see if it can find anything in WEB-INF/classes

I've been out of doing web-apps for a few months and apparently losing knowledge rapidly; is there something obvious I should be looking for?

Thanks
Galen Palmer
Greenhorn

Joined: Aug 09, 2007
Posts: 29
I'm a little confused by the terminology you used in describing the problem: You say that the "main" jar is in the libs directory. When I look at my deployed web app in 5.5.23 I only see supporting jars in the lib directory. The "main" classes are arrayed in the classes directory.

Anyway, here's my questions for you: are you seeing resources deployed in the classes directory structure for the deployed app? And, are the classes that are attempting to access those resources in the classes directory or are they packaged up in a jar in the lib directory?

For the record, I'm using maven 2 for the war generation and hibernate (data access) and spring framework (MVC) and these libraries have no problem seeing the hibernate.hbm.xml, for example, file that are at the root of my classes directory.

Apologies in advance if I'm misunderstanding your setup...
Bob Peterson
Ranch Hand

Joined: Jul 30, 2004
Posts: 47
Galen, thanks for your reply

Our 'main' jar is built by a completely separate project. I'm trying to mock-up a web app that a customer of ours might construct, so I'm assuming they would put our 'main' jar along with other supporting jars (like log4j, or axis, db drivers, etc.) in WEB-INF/lib.

Yes, the resources (i.e. log4j.xml) are deployed in the classes directory. Yes, the classes that are trying to access those resources are packaged in our 'main' jar, which is in WEB-INF/lib. I'm able to successfully use various other classes from that main jar in the jsp.
Galen Palmer
Greenhorn

Joined: Aug 09, 2007
Posts: 29
I've never had a very clear understanding of how resources can be accessed, so I dove into the Hibernate code which I know is working for my webapp. In this case, hibernate.jar is in my WEB-INF/lib directory and my specific configuration resources is in the WEB-INF/classes directory. I think this is similar to the way your app is set up.

Anyway, after diving into the code it looks like the major work is done in a utility class called ConfigHelper here:



I don't fully understand what is going on in all these cases, but I *think* that the logic is involved with making sure that the resource is looked for relative to the application rather that the jar file. (I'm probably not describing this correctly).

I wonder if you modified you main jar to look for resources like Hibernate does if it would work correctly?
Bob Peterson
Ranch Hand

Joined: Jul 30, 2004
Posts: 47
That makes sense. My app's code to find resources is pretty skimpy, so I'll give this a shot. Thanks for posting that.

But why would log4j not be finding the log4j.xml file? I've noticed I'm missing the log4j.dtd, would that do it? I've run some code in the test jsp that is supposed to write out to a log file defined in our log4j.xml and it's not creating that log file.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Tomcat 5.5 not loading resources in WEB-INF/classes