SpringBoot项目如何进行打包部署-jar包

springboot的打包方式有很多种。有打成war的,有打成jar的,也有直接提交到github,通过jekins进行打包部署的。这里主要介绍如何打成jar进行部署。不推荐用war,因为springboot适合前后端分离,打成jar进行部署更合适。
首先需要在application.yml当中配置端口

server:
    port: 8080

maven配置文件

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
		 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<parent>
		<groupId>com.mtons.mblog</groupId>
		<artifactId>mblog</artifactId>
		<version>0.0.1-SNAPSHOT</version>
	</parent>
	<artifactId>web</artifactId>
	<packaging>jar</packaging>

	<dependencies>
		<dependency>
			<groupId>com.mtons.mblog</groupId>
			<artifactId>core</artifactId>
		</dependency>

		<dependency>
			<groupId>com.fasterxml.jackson.core</groupId>
			<artifactId>jackson-core</artifactId>
		</dependency>
		<dependency>
			<groupId>com.fasterxml.jackson.core</groupId>
			<artifactId>jackson-databind</artifactId>
		</dependency>

		<dependency>
			<groupId>org.apache.shiro</groupId>
			<artifactId>shiro-web</artifactId>
		</dependency>
		<dependency>
			<groupId>org.apache.shiro</groupId>
			<artifactId>shiro-spring</artifactId>
		</dependency>
		<dependency>
			<groupId>org.apache.shiro</groupId>
			<artifactId>shiro-ehcache</artifactId>
		</dependency>

	</dependencies>

	<build>
		<finalName>mblog</finalName>
		<resources>
			<resource>
				<directory>src/main/resources</directory>
				<includes>
					<include>**/**</include>
				</includes>
			</resource>
		</resources>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
				<configuration>
					<jvmArguments>-Dfile.encoding=UTF-8</jvmArguments>
					<executable>true</executable>
					<mainClass>mblog.BootApplication</mainClass>
					<includeSystemScope>true</includeSystemScope>
				</configuration>
				<executions>
					<execution>
						<configuration>
							<classifier>exec</classifier>
						</configuration>
					</execution>
				</executions>
			</plugin>
		</plugins>
	</build>
</project>

注意最下面的build这块一定要配置否则打jar的时候会说找不 到主类

在启动类当中加上extends SpringBootServletInitializer并重写configure方法,这是为了打包springboot项目用的。

然后按照顺序运行clean再build,我是用sts

然后就会出来我们需要的jar

然后到这个jar的根目录下执行java -jar smallsystem-0.0.1-SNAPSHOT.jar
这个执行方式windows和linux上都一样

如果是阿里云上的,需要通过阿里云把你指定的端口开放,如果是虚拟机上的,需要把防火墙什么的关掉,开放端口即可。

原文链接:
https://www.jianshu.com/p/c616380095f0

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值