我有这个要求,即我的Web应用程序需要从Tomcat webapps目录之外的属性文件中读取,例如从$ CATALINA_HOME / properties/ myapp.properties中读取。我已经尝试了几件事,但到目前为止还没有运气
有多种方法。
这是一个样本,显示Option 1 and Option 2
Option 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(); }