Reputation: 1627
I'm having some trouble trying to figure out a good way to control which resources to include in a war using maven. In my src/main/resources directory I have two files, logback.xml and logback-test.xml . What I want to be able to do is direct maven which of the two to include in the classpath based on the current maven profile. My initial thought was to define a property called log.config and then use that property in the configuration of maven-war-plugin. Something like:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.3.1</version>
<configuration>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>${log.config}</include>
</includes>
</resource>
</webResources>
</configuration>
</plugin>
and a profile like
<profile>
<id>test</id>
<properties>
<log.config>logback-test.xml</log.config>
</properties>
</profile>
If I run the command
mvn clean package -P test
I still end up with both versions of the logback file in the resulting war. I also tried using
<packagingIncludes>${log.config}</packagingIncludes>
with the same results.
What am I doing wrong here? Is there a better way to include/exclude files without having to copy/paste the maven-war-plugin definition into all my profiles?
Upvotes: 0
Views: 785
Reputation:
You can try pushing resources in the build though the profile (or exclude some):
<profiles>
<profile>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<id>Acceptance</id>
<properties>
<myDatabase.url>jdbc:informix-sqli://Adbhost:Aservice/Adatabase:INFORMIXSERVER=Aifxserver;IFX_LOCK_MODE_WAIT=1</myDatabase.url>
<myDatabase.username>usernamea</myDatabase.username>
<myDatabase.password>pass</myDatabase.password>
</properties>
<build>
<resources>
<resource>
<directory>resources</directory>
<includes>
<include>keypair_rsa_acceptance.p12</include>
<include>logback-test.xml</include>
</includes>
<excludes>
<exclude>logback.xml</exclude>
</excludes>
</resource>
</resources>
</build>
</profile>
<profile>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<id>Production</id>
<properties>
<myDatabase.url>jdbc:informix-sqli://Pdbhost:Pservice/Pdatabasep:INFORMIXSERVER=Pifxserver</myDatabase.url>
<myDatabase.username>usernamep</myDatabase.username>
<myDatabase.password>pass</myDatabase.password>
</properties>
<build>
<resources>
<resource>
<directory>resources</directory>
<includes>
<include>keypair_rsa_production.p12</include>
<include>logback.xml</include>
</includes>
<excludes>
<exclude>logback-test.xml</exclude>
</excludes>
</resource>
</resources>
</build>
</profile>
</profiles>
Upvotes: 1