Skip to main content

11 SpringBoot打包

1 Build an executable JAR

You can run the application from the command line with Gradle or Maven. You can also build a single executable JAR file that contains all the necessary dependencies, classes, and resources and run that. Building an executable jar makes it easy to ship, version, and deploy the service as an application throughout the development lifecycle, across different environments, and so forth.

If you use Gradle, you can run the application by using ./gradlew bootRun. Alternatively, you can build the JAR file by using ./gradlew build and then run the JAR file, as follows:

java -jar build/libs/gs-accessing-data-jpa-0.1.0.jar

If you use Maven, you can run the application by using ./mvnw spring-boot:run. Alternatively, you can build the JAR file with ./mvnw clean package and then run the JAR file, as follows:

java -jar target/gs-accessing-data-jpa-0.1.0.jar

2 FQA

2.1 SpringBootGradle 打包时,避免测试用例

$ ./gradlew clean build -x test

2.2 关掉springBoot的进程

$ kill -9 $(lsof -i -P | grep 8080  | awk '{print $2}') # mac OS

3 Gradle 其它用法

 $ ./gradlew bootRun # 启动项目
$ ./gradlew bootJar # 打成jar包
$ ./gradlew bootBuildImage --imageName=imageName #打包成docker镜像

4 jar包启动参数

$ java -Duser.timezone="Asia/Shanghai" -jar <jar file> # 设置时区

参考资料