gpt4 book ai didi

maven-2 - Maven 资源不复制文件

转载 作者:行者123 更新时间:2023-12-03 21:45:43 27 4
gpt4 key购买 nike

我想使用 maven 替换我的 war 文件中的一些 *.properties 文件。

因此,我在资源文件夹中创建了文件夹 dev、test 和 prod。现在,在执行相应的配置文件时,我只想在我的 war 文件中的资源文件夹路径中使用这些文件夹之一。结果是 maven 也在复制所有其他文件夹,因此它们在类路径中是双倍的。这是我的配置:

<profile>
<id>dev</id>

<activation>
<activeByDefault>true</activeByDefault>
</activation>

<build>
<plugins>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<id>copy-dev-resources</id>
<phase>process-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>

<overwrite>true</overwrite>

<outputDirectory>${basedir}/target/classes</outputDirectory>
<resources>
<resource>
<!-- source -->
<directory>src/main/resources/dev</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>

我现在如何配置 Maven,它只将文件夹 src/main/resources/dev 的内容复制到目标/类?

谢谢你的帮助

最佳答案

Maven 默认将“src/main/resources”中的所有文件复制到输出文件夹,因此在您当前的配置中,它可能会创建“dev”、“test”和“prod”文件夹及其内容,然后另外复制开发资源没有“dev”前缀。

我建议保留默认资源文件夹,并将其仅用于与配置文件无关的资源。然后,您可以在您的个人资料中配置其他资源文件夹:

<profile>
<id>dev</id>
<build>
<resources>
<resource>
<directory>${basedir}/src/main/resources-dev</directory>
</resource>
</resources>
</build>
</profile>

还应该可以使用配置文件中定义的属性在公共(public)构建部分中配置它:
<build>
<resources>
<resource>
<directory>${basedir}/src/main/resources-${projectStage}</directory>
</resource>
</resources>
</build>
<profiles>
<profile>
<id>dev</id>
<properties>
<projectStage>dev</projectStage>
</properties>
</profile>
</profiles>

如果由于某种原因无法更改当前目录结构,则必须为默认资源文件夹配置排除项,以不复制嵌套的配置文件相关文件夹:
    <build>
<resources>
<resource>
<directory>${basedir}/src/main/resources</directory>
<excludes>
<exclude>dev/**</exclude>
<exclude>test/**</exclude>
<exclude>prod/**</exclude>
</excludes>
</resource>
</resources>
</build>

关于maven-2 - Maven 资源不复制文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8727058/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com