springBoot项目打包idea有什么方法

小编给大家分享一下springBoot项目打包idea有什么方法,希望大家阅读完这篇文章后大所收获,下面让我们一起去探讨吧!

War包

1.首先在启动类继承SpringBootServletInitializer

@SpringBootApplication
public class DemoApplication extends SpringBootServletInitializer {
	@Override
	protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
		return application.sources(DemoApplication.class);
	}
	public static void main(String[] args) {
		SpringApplication.run(DemoApplication.class, args);
	}
}

2.把项目pom文件改成war文件

<groupId>com.code</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>

3.加入tomcat去猫依赖

<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-tomcat</artifactId>
	<scope>provided</scope>
</dependency>

点击右键项目
然后点击OPen Module Settings(或者直接按F4)
点击Artifatcs ===》点击+号》Web Application:Exploded》点击from Modules…
然后再点击+号》Web Application:Archive》点击第二项
点击勾选Include in project build
点击右下角 Apply》OK
然后回主页点击工具栏中的Build》build Artifatcs ==》all Artifatcs ==》build
等待执行就成功啦
然后把打包好的项目放入tomcat中的webapp目录下,运行

Jar包

方法一

不用其他操作,直接
点击右键项目
然后点击OPen Module Settings(或者直接按F4)
点击Artifatcs ===》点击+号 ==》JAr》点击from Modules with dependencies…
然后弹出页面
在Main Class选中驱动类
在jar file from libraries 单选中 copy to the output directory and link via manifest,点击OK
点击勾选Include in project build
点击右下角 Apply》OK
然后回主页点击工具栏中的Build》build Artifatcs ==》all Artifatcs ==》build
等待执行就成功啦

把架包全部拷贝出来
使用命令
java -jar xxx.jar xxx为你的项目包名

方法二

点击右侧Maven projects
打开Lifecycle , 把上面闪电图标点亮
双击clean 清空原先的,成功后

双击package 等待执行打包成功

看完了这篇文章,相信你对springBoot项目打包idea有什么方法有了一定的了解,想了解更多相关知识,欢迎关注行业资讯频道,感谢各位的阅读!