Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

referencing configuration.properties outside of the .war

Tags:

i want to deploy a war and the war should fetch some properties from outside the war (lets say where the .war file is, that same directory.)

at the moment this is the best solution i have found:

<context:property-placeholder location="file:${user.home}/configuration.properties" ignore-unresolvable="true"/>

but this solution forces me to keep it always in the home directory. i want it to be in the tomcat webapps directory where i deploy my .war. I am only looking for a solution that involves absolute path. if relative path is absolutely impossible, then i will consider an absolute path.

thanks in advance.

like image 535
Ikthiander Avatar asked Feb 03 '11 10:02

Ikthiander


People also ask

How do you read Properties filed outside war?

Provide the file name using context param or java system parameter. But, it is again property file location is war dependent. You should change war file to change propert file location. If i am correct the requirement was to change the props in the file , not the file as such.

Where to place properties file in tomcat?

It doesn't "go in Tomcat". It goes in the web application (WAR). The best place to put a properties file would be in the webapp's WEB-INF/classes directory, which is part of the application classpath.


1 Answers

here is one solution:

<context:property-placeholder 
     location="file:${catalina.home}/webapps/datasource.properties"
     ignore-unresolvable="true"/>

let me know if there is anything better, for example if i can get rid of catalina home reference and make it a more general one somehow.

like image 93
Ikthiander Avatar answered May 10 '23 17:05

Ikthiander