File reading in a .war file?

D

ddog

Hi,
I've been tasked with writing code that simply reads values from a
properties file. The executing code will reside in a .war file and be
run on JBoss. I'm not able to test the code under JBoss at this time.
The code below works properly when tested via a main() method but I've
read there may be issues running it in a .war file. Can someone tell
me if this is the preferred method to do this under my circumstances?
I don't want to turn this in and have it blow up when it's deployedm :
(


FileInputStream fp =new FileInputStream(PROPERTIES_FILE);
Properties props =System.getProperties();
props.load(fp);

Thanks in advance!
 
D

Daniel Pitts

Hi,
I've been tasked with writing code that simply reads values from a
properties file. The executing code will reside in a .war file and be
run on JBoss. I'm not able to test the code under JBoss at this time.
The code below works properly when tested via a main() method but I've
read there may be issues running it in a .war file. Can someone tell
me if this is the preferred method to do this under my circumstances?
I don't want to turn this in and have it blow up when it's deployedm :
(

FileInputStream fp =new FileInputStream(PROPERTIES_FILE);
Properties props =System.getProperties();
props.load(fp);

Thanks in advance!

You are better off putting the file into the class path, and use
InputStream fp
MyClass.class.getClassLoader().getResourceAsStream(PROPERTIES_FILE);

Also, I would think its a bad idea to load your properties file in
with the System properties file, unless you REALLY want to do that.

Alternatively, if its just a few properties, and they should be in the
system properties, you might consider simply modifying the script you
use to start JBoss and add -Dprop.name=value for the properties you
want to set.
 

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

Staff online

Members online

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top