[英]How to include specific files in war using maven
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.我在尝试找出一种使用 maven 控制战争中包含哪些资源的好方法时遇到了一些麻烦。在我的 src/main/resources 目录中,我有两个文件,logback.xml 和 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.
我希望能够做的是直接 maven 根据当前的 maven 配置文件将两者中的哪一个包含在类路径中。 My initial thought was to define a property called log.config and then use that property in the configuration of maven-war-plugin.
我最初的想法是定义一个名为 log.config 的属性,然后在 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
mvn clean package -P 测试
I still end up with both versions of the logback file in the resulting war.在由此产生的战争中,我仍然得到了两个版本的 logback 文件。 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?
有没有更好的方法来包含/排除文件而不必将 maven-war-plugin 定义复制/粘贴到我的所有配置文件中?
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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.