I am reading a properties file from the Tomcat\\conf\\somename.properties
directory using
String demo = System.getProperty(\"catalina.base\") +
Simply put, don't rely on catalina.base
, that is your first problem :)
Or, more precisely, the java servlet api gives you access to resources inside your web application, so your app is truly portable (not only between servers, but also you can put it anywhere on the file system, zipped as a war or exploded)
Say you put your file at
, then this is what you do in your servlet, listener, or other web-aware classes:
getServletContext().getResourceAsStream("/WEB-INF/somename.properties");
See similar question here.
Another alternative is to use regular java api to search for files in your classpath, e.g. this.getClass().getResource("/somename.properties")
. In the case of a web application, this will find such a file located under /WEB-INF/class/
or any jar under /WEB-INF/lib/
.
Finally, if you can't put the file inside your web application, you can put it anywhere on the hard drive and use some config param (e.g. a system property, or a context parameter in web.xml) to refer to it.