How to add external resources (properties file) on to the classpath so that war can read?

懵懂的女人 提交于 2019-12-23 23:25:05

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!