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!
至此,部署成功~