Springboot项目打包部署通过Java-jar运行
程序员文章站
2024-02-02 22:52:16
...
尊重原创: https://blog.csdn.net/shimilysj/article/details/79838124
springboot的打包方式有很多种。有打成war的,有打成jar的,也有直接提交到github,通过jekins进行打包部署的。这里主要介绍如何打成jar进行部署。不推荐用war,因为springboot适合前后端分离,打成jar进行部署更合适。
首先需要在application.properties当中配置端口
server.port=8080
# http://localhost:8088/swagger-ui.html
- 1
- 2
marven的配置文件
<?xml version="1.0" encoding="UTF-8"?>
<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>
<groupId>com.weixin</groupId>
<artifactId>smallsystem</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>smallsystem</name>
<description>smallsystem</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.2.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.2.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.weixin.SmallsystemApplication</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</project>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
注意最下面的build这块一定要配置否则打jar的时候会说找不 到主类
在启动类当中加上extends SpringBootServletInitializer并重写configure方法,这是为了打包springboot项目用的。
package com.weixin;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
@SpringBootApplication
public class SmallsystemApplication extends SpringBootServletInitializer{
public static void main(String[] args) {
SpringApplication.run(SmallsystemApplication.class, args);
}
@Override//为了打包springboot项目
protected SpringApplicationBuilder configure(
SpringApplicationBuilder builder) {
return builder.sources(this.getClass());
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
然后按照顺序运行mvn clean再mvn install,我是用idea执行的
然后就会出来我们需要的jar
然后到这个jar的根目录下执行java -jar smallsystem-0.0.1-SNAPSHOT.jar
这个执行方式windows和linux上都一样
如果是阿里云上的,需要通过阿里云把你指定的端口开放,如果是虚拟机上的,需要把防火墙什么的关掉,开放端口即可。
上一篇: 尴尬的无人零售能借5G之力“复苏”吗?
下一篇: 详解ES6中的三种异步解决方案
推荐阅读
-
Springboot项目打包部署通过Java-jar运行
-
jenkins部署SpringBoot的jar包项目到docker容器并运行
-
将bootdo(基于springboot的项目)打包上传并运行于阿里云服务器
-
SpringBoot+Docker实现项目的Maven打包&镜像构建&容器中运行==简单自动化部署
-
springBoot项目打war包,部署到外部tomcat;解决打包后resources下的文件全部丢失
-
SpringBoot项目打包部署
-
SpringBoot项目如何打包部署
-
springboot项目打包部署和删除
-
SpringBoot项目打包并部署
-
【个人springboot项目】打包部署