When you develop a webapp with a scripting language you have a file in your project's directory tree where configurations are defined at deploy time and read for initialization at runtime. Things change significantly when you deploy your webapp as a compiled WAR file, because you neither have access to any directory tree nor typically edit the content of the archive.
This is my scenario: my app needs smtp.properties
for sending emails at runtime, so this file contains somehow sensitive information which I don't want to share with other webapps. This means that I won't put the file in the $CLASSPATH
. Another option is checking in a known location, but this has obvious portability issues. Just to name one: on Linux you have /etc
, on Windows there is no /etc
Currently I read the settings with ServletContext.getInitParameter(String)
, but this impose a constraint on the data format and the actual file's place depends on the servlet container.
So my final answer is: what is the closest match to config.php
(or config.yml
) in JavaEE's land?
Disclaimer: I read lots of similar question, and it seems that the short answer is no way. This is also cumbersome when you wish to override the settings for other components at deploy time (like logging)