2

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

Rama Krishna. G
  • 526
  • 2
  • 8
  • 24
  • Related: https://stackoverflow.com/questions/17670826/adding-a-directory-to-tomcat-classpath-and-read-the-property-file-in-spring and https://stackoverflow.com/questions/1300780/adding-a-directory-to-tomcat-classpath – Vadzim Nov 17 '17 at 12:58

3 Answers3

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)
Suvi
  • 66
  • 5
0

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
chengpohi
  • 14,064
  • 1
  • 24
  • 42
  • I have one file in C:\abs\config.properties. How can I add this on to the classpath ? Some one is guiding from this link (http://stackoverflow.com/questions/1300780/adding-a-directory-to-tomcat-classpath) like set CLASSPATH=C:\abs\config.properties. Does that work ? – Rama Krishna. G Apr 14 '16 at 06:42
  • @RamaKrishna.G, sorry I have not used `set CLASSPATH=`, for our project we are using `catalina.properties` for extra properties. but I think `CLASSPATH` it should can work. – chengpohi Apr 14 '16 at 06:55
  • If I want to use catalina.properties to add my directory, how can I do that ? Can you share me a piece of code ? – Rama Krishna. G Apr 14 '16 at 06:57
0

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.

Vadzim
  • 24,954
  • 11
  • 143
  • 151