I have this requirement that my webapp needs to read from a properties file outside the Tomcat webapps directory, for example from $CATALINA_HOME/properties/myapp.properties. I have tried several things but so far no luck
There are multiple approaches .
Heres a sample ,that showsOption 1 and Option 2
try {
//Use Any Environmental Variable , here i have used CATALINA_HOME
String propertyHome = System.getenv("CATALINA_HOME");
if(null == propertyHome){
//This is a system property that is passed
// using the -D option in the Tomcat startup script
propertyHome = System.getProperty("PROPERTY_HOME");
}
String filePath= propertyHome+"/properties/myapp.properties";
Properties property = new Properties();
property.load(SystemTest.class.getClassLoader().getResourceAsStream(filePath));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
I prefer the option to configure via Tomcat context descriptors.
These XML-documents are placed into the folder tomcat/conf/Catalina/<host>/*.xml
This refers to: Externalizing Tomcat webapp config from .war file
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With