After deployment JDBC.Properties outside .Jar not found by Spring anymore
lately a requirement came up to outsource the database settings out of Spring applicationContext.xml. Therefore we wanted to have a jdbc.properties file outside the builded jars, so the user can easily change the jdbc.settings. So far all worked fine within the eclipse workspace, but as soon as I build the distribution with ant, the applicationContext.xml doesnt find the jdbc.properties anymore.
The applicationContext.xml looks like the following:
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<value>classpath:jdbc.properties</value>
</property>
</bean>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${jdbc.driver}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.user}"/>
<property name="password" value="${jdbc.password}"/>
</bean>
Within eclipse I used following classpath, so the jdbc.properties (which is placed in an eclipse project folder "config") gonna get found:
classpath file:
<classpath>
...
<classpathentry kind="src" path="config"/>
...
</classpath>
Until here all works fine. Now I build the project with Ant. The project.jar gets created, and a seperate config folder right next to it as well with the jdbc.properties file in it. Within the Manifest.mf there is an entry:
config/jdbc.properties
But when I now start the server, the jdbc.properties are not found. I noticed, when I change the Manifest.mf entry to:
config/.
it works fine again. But I dont understand why this is different. Can anyone explain me this behaviour? Or maybe even knows what I am doing wrong? Obviously I have to change the Ant file somehow, so he just adds the config folder in the manifest file, and not only the jdbc.properties-file itself?
Thank you in adv开发者_如何学JAVAance!
The classpath holds the locations of jar files and directories holding class files and other resources. You should specify in your classpath the path to the directory holding the properties file, rather than the path to the properties file itself. That is, your manifest entry should be 'config'.
Solution was to define an classpathelement within the Ant-buildscript.
<classpath>
<pathelement location="${dir.build}/config/."/>
<classpath>
Unfortunatly I still dont know, why refering directly to the file didnt solve this issue as well.
精彩评论