Why can't my properties file be found?

L

laredotornado

Hi,

I'm building a WAR file and trying to figure out where I can put my
properties files within it such that they will be available on the
classpath. Currently, I've tried WEB-INF/classes/mine.properties and
WEB-INF/lib/mine.properties without luck. That is, after I deploy my
WAR file and access my JSP with this code:

java.util.Properties props = new java.util.Properties();
ClassLoader cl = this.getClass().getClassLoader();
InputStream input =
cl.getResourceAsStream( "mine.properties" );
if (input == null) {
out.println("can't find properties.");
} else {
props.load(input);
out.println(props);
} // if


what is printed out is "can't find properties". I'm sure I'm missing
something really obvious. Your help is appreciated, - Dave
 
N

Nigel Wade

laredotornado said:
Hi,

I'm building a WAR file and trying to figure out where I can put my
properties files within it such that they will be available on the
classpath. Currently, I've tried WEB-INF/classes/mine.properties and
WEB-INF/lib/mine.properties without luck.
That is, after I deploy my
WAR file and access my JSP with this code:

java.util.Properties props = new java.util.Properties();
ClassLoader cl = this.getClass().getClassLoader();
InputStream input =
cl.getResourceAsStream( "mine.properties" );

This will look for the file "mine.properties" in the same directory as the class
file for "this". If the class is in the package my.package then it will
actually be looking for the file WEB-INF/classes/my/package/mine.properties.

Given that you have put the class file in WEB-INF/classes (i.e. the root of the
class hierarchy) you should be able to specify "/mine.properties".
 
L

laredotornado

laredotornadowrote:



This will look for the file "mine.properties" in the same directory as the class
file for "this". If the class is in the package my.package then it will
actually be looking for the file WEB-INF/classes/my/package/mine.properties.

Given that you have put the class file in WEB-INF/classes (i.e. the root of the
class hierarchy) you should be able to specify "/mine.properties".

Is there anywhere you can put the file within the WAR such that you
can specify only "mine.properties"? - Dave
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top