alekz
alekz

Reputation: 116

Deployment web-application on application server. Database access credentials

I have a web application which I deploy on Tomcat Server manually.

My property file with database credentials is not located in classpath. On startup I load it like this:

prop.load(new FileInputStream("C:\\application.property"));

Downback of this is that now I can move my code to linux based platform without changing the source.

If I put this file to classpath it will be packed inside war (with all credentials) and replaced every time I redeploy my application. Tomcat is deleting application dir and replace it with war content on redeploy.

The question is: How and where to put property file in classpath and ensure that this file will not be replaces/deleted by application server on application redeployment. And the file must not be inside war.

Upvotes: 1

Views: 88

Answers (1)

Andremoniy
Andremoniy

Reputation: 34900

The thing which you are doing looks like anti-pattern. Do not store database connection credentials in external property file.

Database access credentials should be placed inside context.xml configuration file of your tomcat. This is called JNDI Resources and you can read about it, for example, here.

Upvotes: 2

Related Questions