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?
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.
Sometimes we have to configure property files from outside of classpath so that anyone can access this file without looking into application.
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.
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!
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With