2

To load environment specific values, in my src/main/resources folder, I have some properties files in different subfolders i.e.

  • com/app/ws/webservices-dev.properties
  • com/app/ws/webservices-test.properties
  • com/app/jms/jms-dev.properties
  • com/app/jms/jms-test.properties

I am loading these properties through spring

<bean id="placeholderProperties" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
        <list>              
            <value>classpath:/com/app/jms/jms-${ENVIRONMENT:dev}.properties</value>
            <value>classpath:/com/app/ws/webservices-${ENVIRONMENT:dev}.properties</value>
        </list>
    </property>
    <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
    <property name="ignoreResourceNotFound" value="true" />
    <property name="ignoreUnresolvablePlaceholders" value="true" />
    <property name="order" value="0" />
</bean>

ENVIRONMENT is environment variable.

I am using appassembler-maven-plugin to generate the executable .sh file.

       <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>appassembler-maven-plugin</artifactId>
            <version>1.2.2</version>
            <configuration>
                <binFileExtensions>
                    <unix>.sh</unix>
                </binFileExtensions>
                <programs>
                    <program>
                        <mainClass>com.app.MainApp</mainClass>
                        <name>MainApp</name>
                    </program>
                </programs>
            </configuration>
        </plugin>

As a result of this all my properties files become part of my generated jar file. I want to expose some of the properties to set their values at deployment time. I have tried following configuration

       <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>appassembler-maven-plugin</artifactId>
            <version>1.2.2</version>
            <configuration>
                <configurationSourceDirectory>src/main/resources/com/app/bootstrap</configurationSourceDirectory>
                <configurationDirectory>conf</configurationDirectory>
                <copyConfigurationDirectory>true</copyConfigurationDirectory>
                <includeConfigurationDirectoryInClasspath>true</includeConfigurationDirectoryInClasspath> 
                <binFileExtensions>
                    <unix>.sh</unix>
                </binFileExtensions>
                <programs>
                    <program>
                        <mainClass>com.app.MainApp</mainClass>
                        <name>MainApp</name>
                    </program>
                </programs>
            </configuration>
        </plugin>           

But Spring does not load the properties; maybe due to the given path in spring config (see above).

What maven configuration should I use to move my properties files in appassembler\conf folder during package time and have spring load them from the classpath. I am after the configuration that works for both development(in eclipse, unit tests as maven builds) and in deployment.

datguy
  • 623
  • 8
  • 24
amique
  • 2,176
  • 7
  • 34
  • 53
  • If you have the resources in src/main/resources the property files will be packaged already into your jar file as you mentioned. That means the jar is on your classpath which means it should working to load the properties via the classpath. But what i didn't understand is the given configurationSource /../bootstrap? – khmarbaise Jun 06 '12 at 06:56
  • thanks khmarbaise. Packaging of properties file in jar is the problem that I want to overcome. Properties are packed in jar and they can not be changed at deployment time. i want to put them out of jar file. "configurationSource /../bootstrap" the bootstrap is my resource folder having properties files. this configuration copies the properties in conf folder of assembly – amique Jun 07 '12 at 01:14
  • Hm. For unit tests you should locate your properties into src/test/resources instead. If you don't like to be the properties packaged into the jar you need to locate them into a different location and handle it yourself (as in appassembler plugin src/main/config is the default for configurationSourceDirectory). BTW: I've written blog article about such kind of problem (http://blog.soebes.de/index.php?/archives/340-Maven-Configuration-For-Multipe-Environments.html). – khmarbaise Jun 07 '12 at 09:48
  • but how can I add conf directory in classpath? – amique Jan 18 '13 at 04:52

0 Answers0