一、jar包導出
使用IDEA內置導出工具會報錯
1.安裝maven
http://maven.apache.org/download.cgi
下載 Binary zip archive
配置環境變量
“新建系統變量”中輸入變量名MAVEN_HOME,並將變量值設置為安裝路徑,在這里為D:\apache-maven-3.3.9
“Path變量”,在其變量值的末尾加上%MAVEN_HOME%\bin(注意:跟前面變量值要以英文分號間隔)。
mvn -v 查看安裝成功
附,如果導出的war包靜態文件不全需要配置pim.xml中的<resources></resources>,**/*.*這里配置的是將二級目錄所有類型文件導出,*.yml是導出.yml類型文件。
<build> <finalName>patentManagementSystem</finalName> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <includeSystemScope>true</includeSystemScope> </configuration> </plugin> </plugins> <resources> <resource> <directory>src/main/resources</directory> <includes> <include>**/*.*</include> <include>*.yml</include> </includes> <filtering>false</filtering> </resource> <resource> <directory>src/main/java</directory> <includes> <include>**/*.properties</include> <include>**/*.xml</include> </includes> <filtering>false</filtering> </resource> </resources> </build>
2.進入項目目錄下
mvn clean package
3.生成的jar包會在target文件夾里
附
報錯
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.4.7.RELEASE:repackage (default) on project patentManagementSystem: Execution default
of goal org.springframework.boot:spring-boot-maven-plugin:1.4.7.RELEASE:repackage failed: Unable to find a single main class from the following candidates [com.patent.p
atentManagementSystem.PatentManagementSystemApplication, com.patent.patentManagementSystem.util.ExcelUtil, com.patent.patentManagementSystem.util.NewExcelUtil] -> [Help
1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException
由於main函數過多,需要指定main函數
mvn clean package -Dstart-class=com.patent.patentManagementSystem.PatentManagementSystemApplication
二、war包導出(最后訪問路徑肯會報錯)
Pom.Xml配置
1.加入<packaging>war</packaging>

2.加入
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<!--打包的時候可以不用包進去,別的設施會提供。事實上該依賴理論上可以參與編譯,測試,運行等周期。
相當於compile,但是打包階段做了exclude操作-->
<scope>provided</scope>
</dependency>

3.加入
<!-- 應與application.properties(或application.yml)中context-path保持一致 -->
<finalName>patentManagementSystem</finalName>

二、新建ServletInitializer類

import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; public class ServletInitializer extends SpringBootServletInitializer { @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(Application.class); } }
三、 添加Artifact









改名去掉war;勾選show content of elements

刪除WEB-INF





刪除WETA-INF文件夾



(a)、就是靜態文件資源 訪問404
參考
https://blog.csdn.net/qq_32923745/article/details/78270835
