springboot打jar包部署
阿新 • • 發佈:2018-12-14
最近在做springboot的專案,發現springboot部署的方式還是比較特別的。
因為springboot 內建了tomcat,所以我們只要把它打成jar包即可執行。
下面就說一說jar包執行的方式:
1.單模組專案打包:
pom.xml檔案里加入spring-boot-starter-tomcat依賴與spring-boot-maven-plugin外掛。
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope> </dependency>
<build> <plugins> <!-- springboot 打包的外掛 --> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <!-- 打包的型別,這裡是你的專案主類--> <mainClass>com.cesgroup.eurekaServerDemo.EurekaServerDemoApplication</mainClass> <layout>ZIP</layout> </configuration> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin> </plugins> </build>
然後到路徑目錄下 執行:mvn clean package -DskipTests(-DskipTests是忽略單元測試,你也可以打包上去)。
你會發現 target\ 路徑下已經生成了xxx.jar,雙擊執行即可啟動專案。
其他啟動方法:
到路徑目錄下 java -jar xxx.jar
或者後臺執行的話就 nohup java -jar xxx.jar &
2.多模組專案打包:
pom.xml檔案裡同樣的引入spring-boot-starter-tomcat依賴與spring-boot-maven-plugin外掛。同上
因為是多模組,你要把其他模組引入到所打包的模組中(一般都是web模組)。
<dependency>
<groupId>com.cesgroup.zw.auth</groupId>
<artifactId>auth-center-api</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.cesgroup.zw.auth</groupId>
<artifactId>auth-center-service</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.cesgroup.zw.auth</groupId>
<artifactId>auth-center-commons</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
然後這裡的主類一定是在你所打包的模組裡。
<configuration>
<!-- 打包的型別 -->
<mainClass>com.cesgroup.zw.WebApplication</mainClass>
<layout>ZIP</layout>
</configuration>
其餘同上,大功告成!!!