1、配置好电脑 maven 环境变量
2、项目的maven配置. pom.xml 文件
主要内容:(1) 设置 packaging 为jar (2)configuration 为SpringBoot 项目启动类。
<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.spring.example</groupId>
<artifactId>spring-boot-example</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.10.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<!-- Need this to compile JSP -->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.ServiceApplication</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</project>
3、找到项目在电脑目录
例如:D:\study\workspace\spring-boot-example
4、在项目本地文件夹按住Crtl+Shift+右键打开命令窗口,执行mvn clean package
执行完毕后,在项目文件夹下 ---》target 下会出现一个jar包 spring-boot-example-0.0.1-SNAPSHOT.jar
5、window jar部署启动
在target目录Crtl+Shift+右键打开命令窗口,执行java -jar 项目jar,即可启动服务
例如:java -jar spring-boot-example-0.0.1-SNAPSHOT.jar