我想用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>
Run Code Online (Sandbox Code Playgroud)
现在如何配置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>
Run Code Online (Sandbox Code Playgroud)
还应该可以使用配置文件中定义的属性在公共构建部分中配置它:
<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>
Run Code Online (Sandbox Code Playgroud)
如果由于某种原因无法更改当前目录结构,则必须为默认资源文件夹配置排除项,以便不复制嵌套的与配置文件相关的文件夹:
<build>
<resources>
<resource>
<directory>${basedir}/src/main/resources</directory>
<excludes>
<exclude>dev/**</exclude>
<exclude>test/**</exclude>
<exclude>prod/**</exclude>
</excludes>
</resource>
</resources>
</build>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
20068 次 |
最近记录: |