轉:SpringBoot項目如何進行打包部署

引自:SpringBoot項目如何進行打包部署php

springboot的打包方式有不少種。有打成war的,有打成jar的,也有直接提交到github,經過jekins進行打包部署的。這裏主要介紹如何打成jar進行部署。不推薦用war,由於springboot適合先後端分離,打成jar進行部署更合適。
首先須要在application.properties當中配置端口html

server.port=8080
# http://localhost:8088/swagger-ui.html 

marven的配置文件java

<?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> 

注意最下面的build這塊必定要配置不然打jar的時候會說找不 到主類linux

 

 

 

在啓動類當中加上extends SpringBootServletInitializer並重寫configure方法,這是爲了打包springboot項目用的。git

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()); } } 

而後按照順序運行mvn clean再mvn install,我是用idea執行的github

 

 

 

 

而後就會出來咱們須要的jarweb

 

 

 

而後到這個jar的根目錄下執行java -jar smallsystem-0.0.1-SNAPSHOT.jar
這個執行方式windows和linux上都同樣spring

 

 

若是是阿里雲上的,須要經過阿里雲把你指定的端口開放,若是是虛擬機上的,須要把防火牆什麼的關掉,開放端口便可。apache

相關文章
相關標籤/搜索