SpringBoot 打jar包 部署啓動

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章