IDEA+Springboot 导出jar包,war包

一、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

posted @ 2019-06-22 17:06  键盘已坏  阅读(3522)  评论(0编辑  收藏  举报