我使用 Maven 进行构建,并希望使用 logback-debugging.xml
进行开发,但将另一个 logback-info.xml
打包到最终产品中。
最佳答案
我想出了以下 Maven 配置:
<profile>
<id>development</id>
<activation>
<property>
<name>dev</name>
</property>
</activation>
<build>
<resources>
<resource>
<filtering>true</filtering><!-- if it is neccessary -->
<directory>src/main/logging/develop</directory><!-- from -->
<targetPath>${project.build.outputDirectory}</targetPath><!-- to -->
<includes><!-- what -->
<include>logback.xml</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*</include>
</includes>
</resource>
</resources>
</build>
</profile>
</profiles>
在 Maven 设置文件中,我们可以默认激活一个配置文件:
<settings>
[..]
<activeProfiles>
<activeProfile>development</activeProfile>
</activeProfiles>
[..]
</settings>
另一种方法是将默认配置文件配置移动到“正常”pom 构建部分。
要激活开发配置文件,请通过命令行传递调试标志,例如mvn package -Ddev
关于java - 在生产版本中包含不同的 logback.xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46157041/