0

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?

Stefano Pisano
  • 440
  • 1
  • 8
  • 24

2 Answers2

0

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.

Ironluca
  • 3,402
  • 4
  • 25
  • 32
0

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:

Externalizing Tomcat webapp config from .war file

Community
  • 1
  • 1
Dave Richardson
  • 4,880
  • 7
  • 32
  • 47