springboot系列4-簡化部署
阿新 • • 發佈:2018-11-01
1.匯入生成可執行jar包的依賴
開啟pom.xml檔案,新增:
<!-- Package as an executable jar -->
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</ build>
2.打包
輸出以下內容表示構建成功:
[INFO] Building jar: D:\work\workspace\springboot\spring-boot-01-helloworld\target\spring-boot-01-helloworld-1.0-SNAPSHOT.jar [INFO] [INFO] --- spring-boot-maven-plugin:2.0.6.RELEASE:repackage (default) @ spring-boot-01-helloworld --- [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 2.642 s [INFO] Finished at: 2018-10-24T21:54:07+08:00 [INFO] ------------------------------------------------------------------------ Process finished with exit code 0
將目錄下的D:\work\workspace\springboot\spring-boot-01-helloworld\target\spring-boot-01-helloworld-1.0-SNAPSHOT.jar 拷貝到測試目錄,執行jar包:
java -jar .\spring-boot-01-helloworld-1.0-SNAPSHOT.jar
瀏覽器中執行localhost:8080/hello測試,輸出Hello world!
至此,部署成功~