Problem getting properties file from webapp in tomcat

I developed a web application that works fine in JBoss 4. Now I need to get it to work in Tomcat 6, but it's hard for me to access some properties file. To read these files, I use the following code:

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

As I said, it works fine in JBoss 4. But when I deploy my application to tomcat, it does not find the file, assigning the null value to the 'is' variable, which triggers StartupError. The file is located in the WEB-INF / config directory, and webapp is deployed as a war.

Any solution to this problem?

Thank you, Alexander

+4
source share
2 answers

Place the property files in WEB-INF / classes.

Or include them in the root of one of your Jar Webapp files, although this makes them difficult to edit. This is good if you select properties inside the script assembly and do not want to edit them after deployment.

+3
source

I assume that Tomcat does not add WEB-INF / config to your webapp class path.

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 one instance of Tomcat 6. All unpacked classes and resources in the / WEB -INF / classes directory of your web application archive, as well as classes and resources in the JAR files in the / WEB directory -INF / lib of your web application archive becomes visible to the containing web application, but not to anyone else.

0
source

All Articles