26

I am trying to read the test1.properties file which is located at an external folder.

here is my spring config file:

<bean id="propertyConfigurer3" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="ignoreUnresolvablePlaceholders" value="true"/>
    <property name="locations">
        <list>
            <value>classpath:test.properties</value>
            <value>classpath:test1.properties</value>
        </list>
    </property>
</bean>

if I place the test1.properties in the tomcat7/lib folder, I am able to read it. However, I want to place it in a different directory as tomcat7/env/test1.properties

I have added the path to the the conf/catalina.properties:

common.loader=${catalina.base}/lib,${catalina.base}/lib/*.jar,${catalina.home}/lib,${catalina.home}/lib/*.jar,${catalina.home}/env

This its not working, please help


solution: Ok.. finally fixed it.. I had been doing it correctly this whole time.. it was my IDE which caused the problem. The IDE was not picking up the changes in the catalina.properties file. I had to delete the server config in my IDE and re configure it.

these links were helpful in general:

Community
  • 1
  • 1
user1561521
  • 283
  • 1
  • 3
  • 7
  • 4
    You could also use the `file:` prefix to point to a file. – Bart Apr 08 '14 at 22:48
  • possible duplicate of [Problems with classpath between Eclipse, Tomcat and JUnit in Spring 3 app](http://stackoverflow.com/questions/4179767/problems-with-classpath-between-eclipse-tomcat-and-junit-in-spring-3-app) – Paul Sweatte Oct 09 '14 at 00:40
  • The question is answered in the comments. See http://meta.stackoverflow.com/questions/251597/question-with-no-answers-but-issue-solved-in-the-comments – Andrés Oviedo Oct 28 '14 at 12:10

3 Answers3

4

Ok.. finally fixed it.. I had been doing it correctly this whole time.. it was my IDE which caused the problem. The IDE was not picking up the changes in the catalina.properties file. I had to delete the server config in my IDE and re configure it.

these links were helpful in general:

Adding a directory to tomcat classpath

http://www.mulesoft.com/tomcat-classpath#solutions

Andrés Oviedo
  • 1,237
  • 12
  • 28
3

Use setenv.sh in the bin directory. If the file doesn't exist, create it. To add something to the classpath use the following syntax:

CLASSPATH=/yourdir/

For windows: setenv.bat

Solution: creating the setenv.bat file under tomcat bin folder helped me in WINDOWS.

DKS
  • 3
  • 3
Peter De Winter
  • 1,082
  • 2
  • 14
  • 26
0

If your intention to keep file outside the war or ear , so that you can update it without compling and creating war again. just editing the file and restarting the server. Keep it in any external folder , even outside server and give absolute path in spring.

<bean id="propertyConfigurer3" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="ignoreUnresolvablePlaceholders" value="true"/>
<property name="locations">
    <list>
        <value>classpath:test.properties</value>
        <value>**file:/someexteranal/dir/test1.properties**</value>
    </list>
</property>

Best thing , you can give this / path with root in Unix/linux and same will work in windows, just need to keep file in directory where your server is installed. Like your tomcat in D drive , then keep it in D:\someexternal\dir and above code will work fine there too

Panther
  • 3,124
  • 9
  • 25
  • 47