![](/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.