1

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.

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.