donderdag 1 juli 2010

Using property file outside of runnable JAR with spring

What I needed to deliver was quite simple, a runnable jar file configured by a property file located in the same directory as the jar file.

As it turns out, the classpath of runable jar files does not include the execution directory, so i needed to come up with another solution.

That solution turned out to be as simple as the problem, apart from the fact that i spent half a day to figure it out. This was the bean description in the spring context.xml :

<bean id="placeholderConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:environment.properties"/>
</bean>

and this is what it should look like to get spring to load the property file from the execution path :

<bean id="placeholderConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="file:environment.properties"/>
</bean>

Geen opmerkingen: