![](/img/trans.png)
[英]cannot get resources folder into jar when using spring boot maven plugin
[英]resources in a Spring Boot application are missing from jar file when using Spring Boot Maven Plugin
我在 Maven v3.3.3 中使用 Spring-Boot v1.3.0.M5。 我曾经能够使用此命令从控制台运行我的 Spring Boot(引导)应用程序。
mvn clean package spring-boot:run
但是,我不得不修改我的pom.xml
以考虑不同的环境构建。 特别是,我使用 Maven 配置文件来修改启动应用程序的属性文件。 现在,当我运行前面提到的命令时,启动应用程序无法运行并抱怨以下异常。
引起:java.lang.NumberFormatException:对于输入字符串:“${MULTIPART.MAXREQUESTSIZE}”
我有一个位于src/main/resources/config/application.properties
的属性文件。 这个属性文件有一堆键值对,如下所示。
multipart.maxFileSize=${multipart.maxFileSize}
multipart.maxRequestSize=${multipart.maxRequestSize}
然后在我的pom.xml
,我的构建定义如下。
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>**/*.properties</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
<excludes>
<exclude>**/*.properties</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<profiles>
<!-- development -->
<profile>
<id>env-dev</id>
<activation>
<activeByDefault>true</activeByDefault>
<property>
<name>env</name>
<value>dev</value>
</property>
</activation>
<properties>
<multipart.maxFileSize>250MB</multipart.maxFileSize>
<multipart.maxRequestSize>250MB</multipart.maxRequestSize>
</properties>
</profile>
<!-- staging -->
<profile>
<id>env-stg</id>
<activation>
<activeByDefault>false</activeByDefault>
<property>
<name>env</name>
<value>stg</value>
</property>
</activation>
<properties>
<multipart.maxFileSize>500MB</multipart.maxFileSize>
<multipart.maxRequestSize>500MB</multipart.maxRequestSize>
</properties>
</profile>
<profiles>
我注意到如果我输入mvn clean package
并查看jar
文件, application.properties
文件就在 jar 里面。
但是,如果我输入mvn clean package spring-boot:run
,则applications.properties
文件不在jar 中。 实际上, src/main/resources
下没有任何内容将其放入 jar 文件中。
这个问题对我来说有点烦人,因为如果我想从命令行运行我的启动应用程序,我现在必须做两个步骤。
mvn clean package
java -jar ./target/app-0.0.1-SNAPSHOT.jar
关于我做错了什么的任何想法?
如文档中所述mvn spring-boot:run
在类路径前添加src/main/resources
以默认支持热重载。 您可以轻松关闭此功能
<build>
...
<plugins>
...
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.2.7.RELEASE</version>
<configuration>
<addResources>false</addResources>
</configuration>
</plugin>
...
</plugins>
...
</build>
试试这个:
<resources>
<resource>
<directory>src/main/resources/config</directory>
<filtering>true</filtering>
<includes>
<include>**/*.properties</include>
</includes>
</resource>
</resources>
从Spring Boot 1.3 开始,为了按预期过滤资源,我们必须使用新的@@
格式:
some.key = @value@
而不是经典:
some.key = ${value}
相关 spring-boot 问题: https : //github.com/spring-projects/spring-boot/issues/980
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.