how to get the working directory for a webapp in tomcat?

subzero picture subzero · Dec 7, 2011 · Viewed 18.7k times · Source

I need to put some settings files in the 'working directory' in order to configure my app.

I have tried puting it in ./WEB-INF/ but did not work, any idea where is the 'working directory'?, and, is it a way to get it programatically?

thanks.

Answer

rfeak picture rfeak · Dec 7, 2011

Although I realize you didn't specifically ask this question maybe this will address your real problem ...

Have you considered putting your config files under WEB-INF/classes ? Many configuration files in a web application are loaded as resources, not as "file" objects. If you put your configuration files under WEB-INF/classes they will be available as resources through the ClassLoader.

EDIT: As a side note, there's a slight danger in putting your config files directly under WEB-INF, as they may be exposed to end users by just typing in the correct URL. This depends on other settings in your web container, but it is a real possibility and has happened more than once. Hope you don't do something like keep DB connection info there ...