I have a file config.properties which I use in order toconfigure the db connection in java but when I run the webapp in tomcat it says that the file doesn't exists because it can't find the file
How can I include this file?
I have a file config.properties which I use in order toconfigure the db connection in java but when I run the webapp in tomcat it says that the file doesn't exists because it can't find the file
How can I include this file?
Usually, configuration files are put in the WEB-INF/ and from a servlet we get the stream to the file using ServletContext.getResourceAsStream("/WEB-INF<folder name>/<file name>")
. It is kept in WEB-INF since no file can be accessed from within WEB-INF with browser. This is more or less a standard practice. There is one other option to configure DB connection through DataSource configured into Tomcat.
The problem with keeping config in WEB-INF is that it isn't flexible and requires rebuilds for config changes, such as when moving from one machine to another. This is not good practice.
Take a look at this answer for how to place you config file elsewhere: