问题
We have small problem in adding the external directory (having config.properties) to the classpath. If we add this to the classpath, we should be able to read it in the web application. There are some spring applications in web application which will read the external properties file. I don't find the correct solution any where ? Could you please point me the right direction ?
Thanks, Rama Krishna
回答1:
I had the similar requirement and I did the followings:
1) Added the properties folder path against shared.loader in catalina.properties. Example:
shared.loader="c:/ExternalResource"
2) Then read the properties using the following :-
Thread.currentThread().getContextClassLoader().getResourceAsStream(propertiesFileName)
回答2:
if you are using tomcat, you can edit conf/catalina.properties, and append your properties folder in common.loader, like:
common.loader=...${catalina.base}/myPropertiesFolder
回答3:
It may be sufficient just to copy the properties file to tomcat\lib directory as tomcat\conf\catalina.properties already contains common.loader="${catalina.base}/lib","${catalina.base}/lib/*.jar".
So lib populates to classpath not only any contained jar contents but all contained files too.
See Tomcat Class Loader HOW-TO.
来源:https://stackoverflow.com/questions/36613907/how-to-add-external-resources-properties-file-on-to-the-classpath-so-that-war