views:

538

answers:

2

Hi,

I've developed a web application that worked fine in JBoss 4. Now, I need to make it work in Tomcat 6, but I'm having trouble to access some properties file. I use the following code to read read these files:

InputStream is = Thread.currentThread().getContextClassLoader()
       .getResourceAsStream(fileName);
if (is == null) {
    throw new StartupError("Error loading " + fileName);
}

properties.load(is);

As I've said before, it works fine in JBoss 4. But when I deploy my app in tomcat, it doesn't find the file, assigning null to 'is' variable, causing the StartupError to be thrown. The file is located at WEB-INF/config directory, and the webapp is deployed as a war.

Any solution for this problem?

Thanks, Alexandre

+2  A: 

Put the properties files in WEB-INF/classes.

Or include them in the root of one of your webapp Jar files, although this makes it harder to edit them. This is good if you're selecting properties within a build script and don't want to edit them once deployed.

JeeBee
Hi JeeBee,your solution did work. But do you know why I was able to access files under WEB-INF/config in JBoss, and couldn't make it in Tomcat?
Alexandre
I think the config folder is a JBoss idea, although I would like Tomcat to support it as well.
JeeBee
A: 

I assume that Tomcat does not add WEB-INF/config into your webapp classpath.

from http://tomcat.apache.org/tomcat-6.0-doc/class-loader-howto.html

WebappX - A class loader is created for each web application that is deployed in a single Tomcat 6 instance. All unpacked classes and resources in the /WEB-INF/classes directory of your web application archive, plus classes and resources in JAR files under the /WEB-INF/lib directory of your web application archive, are made visible to the containing web application, but to no others.

ipingu