I have to load Properties file from one of my class which is bundled within a war file placed on JBoss.
Properties prop = new Properties();
prop.load(new FileInputStream(new File("db.properties")));
When im writting this piece of code for file loading, its saying FileNotFoundException, even though file is on root path of war file.I think by default server is trying to find file from some other folder.
Could you please tell me is there any alternative method or is there any way to set the relative path or anything like that.
-
Usage of ServletContext (5 messages)
- Posted by: AHSAN JAMIL QUADRI
- Posted on: February 07 2005 04:02 EST
Threaded Messages (5)
- Re: Usage of ServletContext by vishal jhagadiawala on February 07 2005 04:48 EST
- Usage of ServletContext by AHSAN JAMIL QUADRI on February 07 2005 05:00 EST
- Usage of ServletContext by Sankara Rao Yadavalli on February 07 2005 11:17 EST
- Using ServletContext by Time PassX on February 07 2005 13:42 EST
-
Re: Usage of ServletContext[ Go to top ]
- Posted by: vishal jhagadiawala
- Posted on: February 07 2005 04:48 EST
- in response to AHSAN JAMIL QUADRI
when you are using this code, server is finding db.properties from JVM_HOME.I have to load Properties file from one of my class which is bundled within a war file placed on JBoss.Properties prop = new Properties();prop.load(new FileInputStream(new File("db.properties")));When im writting this piece of code for file loading, its saying FileNotFoundException, even though file is on root path of war file.I think by default server is trying to find file from some other folder.Could you please tell me is there any alternative method or is there any way to set the relative path or anything like that.
-
Usage of ServletContext[ Go to top ]
- Posted by: AHSAN JAMIL QUADRI
- Posted on: February 07 2005 05:00 EST
- in response to AHSAN JAMIL QUADRI
Yeah I know, But what should i do to sort out that thing, Is there any alternative? -
server[ Go to top ]
- Posted by: Ash H
- Posted on: February 07 2005 09:36 EST
- in response to AHSAN JAMIL QUADRI
Hi,
How about putting it in JBoss server classpath.That should work.
Ash -
Usage of ServletContext[ Go to top ]
- Posted by: Sankara Rao Yadavalli
- Posted on: February 07 2005 11:17 EST
- in response to AHSAN JAMIL QUADRI
You can keep the properties file in a jar file and put it in WEB-INF/lib directory. It should able to find the file from your lib directory.
or else,
Keep the file into your WEB-INF/classes directory and refer the path. It should work.
Enjoy.
Sankar.I have to load Properties file from one of my class which is bundled within a war file placed on JBoss.Properties prop = new Properties();prop.load(new FileInputStream(new File("db.properties")));When im writting this piece of code for file loading, its saying FileNotFoundException, even though file is on root path of war file.I think by default server is trying to find file from some other folder.Could you please tell me is there any alternative method or is there any way to set the relative path or anything like that.
-
Using ServletContext[ Go to top ]
- Posted by: Time PassX
- Posted on: February 07 2005 13:42 EST
- in response to Sankara Rao Yadavalli
I know of atleast two ways to use find the properties file:
1) put your "props.properties" file in your WAR classpath, i.e. /WEB-INF/classes dir. Then, you can get the "props.properties" using the following syntax:
InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream("props.properties");
2. put your "props.properties" file anywhere in your WAR file (e.g. /WEB-INF directory). Here is the syntax:
InputStream stream = context.getResourceAsStream("props.properties");