0

I have two configuration properties files and two application Context xml files , ones for test and others for development and I have to specify which filter to use for each case .

I tried to do this but it's not working, it's select the last filter from the pom.xml ,so when i check the files applicationContext.xml in the folder target/classes and /target/test-classes I found the both files had the same values taken from the last filter declared on pom.xml

<plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <version>2.6</version>

        </plugin>
    </plugins>

    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
        </resource>
    </resources>

    <testResources>
        <testResource>
            <filtering>true</filtering>
            <directory>src/test/resources</directory>
        </testResource>
    </testResources>


    <filters>
        <filter>src/test/filters/filter.properties</filter>
        <filter>src/main/filters/filter.properties</filter>
    </filters>

so i wonder if there is a solution to specify for each case the appropriate filter to use ?

blackbuild
  • 5,026
  • 1
  • 23
  • 35
oussama.elhadri
  • 738
  • 3
  • 11
  • 27

1 Answers1

1

You might use profiles.

Unfortunately filters aren't allowed inside profile, so you could use the following workaround:

Outside profiles write:

<filters>
    <filter>src/${switch}/filters/filter.properties</filter>
</filters>

In a main profile write:

<properties>
  <switch>main</switch>
</properties>
<resources>
    <resource>
        <directory>src/main/resources</directory>
        <filtering>true</filtering>
    </resource>
</resources>

in a test profile write:

<properties>
  <switch>test</switch>
</properties>
<testResources>
    <testResource>
        <filtering>true</filtering>
        <directory>src/test/resources</directory>
    </testResource>
</testResources>

Finally run:

mvn install -Pmain

or:

mvn install -Ptest
taringamberini
  • 2,719
  • 21
  • 29