我有多组属性文件smtp,db,src / main / resources目录下的常用设置,我的项目是maven项目jar包 . 我想从jar构建中排除所有这些属性文件,并将所有这些属性文件放在target / conf文件夹中 . 现在我想在执行应用程序jar时将所有这些配置文件提供给我的jar . 怎么做到这一点?我在pom.xml文件中做了很多事情以排除所有这些属性,现在无法将它们提供给生成的jar . 这是为了排除src / main / resources内容
<resources>
<resource>
<directory>src/main/resources</directory>
<excludes>
<exclude>*.properties</exclude>
</excludes>
<filtering>false</filtering>
</resource>
</resources>
Spring启动插件配置
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<executable>true</executable>
</configuration>
</plugin>
Maven资源插件将所有资源文件放在target / conf文件夹下
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>target/conf</outputDirectory>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
1 回答
据我所知
spring-boot-maven-plugin
不支持复制/移动文件(check out the documentation),你可以使用maven-resources-plugin-3.0.2
来做到这一点 .使用以下示例,您可以从
src/main/resources
中排除所有属性文件,并将它们移动到target/conf
. 这里的例子如下:UPDATE
Spring引导提供了一组环境属性(spring boot documentation),可以在插件中添加
spring-boot-maven-plugin
工件 .每个属性文件由逗号
,
分隔 . 以下是从命令行运行的语法:要么
例如,具有完整路径的最终指令将是:
如果从
target
文件夹运行,则无需指定完整路径:欲了解更多信息check out this