Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read properties file placed outside war?

I'm working on a web application these days. That uses only jsps and servlets. It's a small application. Right now I have placed all the DataSource details in DAO utility class. I want to place these details in a properties file that can be placed outside the war, so that depending on the environment we can change these values, without effecting the war. How can I achieve this?

like image 371
user779354 Avatar asked Jun 01 '11 12:06

user779354


People also ask

What is a property file?

Property files are a common method that we can use to store project-specific information. Ideally, we should keep it external to the packaging to be able to make changes to the configuration as and when required.

Why do we have to configure property files outside of Classpath?

Sometimes we have to configure property files from outside of classpath so that anyone can access this file without looking into application.

What is an overview property file?

Overview Property files are a common method that we can use to store project-specific information. Ideally, we should keep it external to the packaging to be able to make changes to the configuration as and when required.

How to get the location of a property file in Java?

You should give property file location as java runtime property to your web container.. Such as, java -DmypropertyFile.location=c:/propertyfile.properties -jar yourContainer.jar Thanks for contributing an answer to Stack Overflow!


1 Answers

Provide the file name using context param or java system parameter.

1.Context Param

<context-param>
<param-name>daofilename</param-name>
<param-value>D:\daofilename.props</param-value>
</context-param>

2.System Parameter

java -Ddao.filename=D:\daofilename.props server
like image 122
Ramesh PVK Avatar answered Sep 30 '22 22:09

Ramesh PVK