Springbootcli 简明教程
Spring Boot CLI - Packaging Application
Spring boot CLI 提供 jar 命令,用于将应用程序打包为 jar 文件。让我们测试 Starter Thymeleaf Project Chapter 中创建的示例项目,以演示 Spring CLI 的打包功能。按照以下步骤打包示例项目。
Output
现在,您可以在 TestApplication 文件夹中看到两个新创建的文件。
-
TestApplication.jar − 可执行 jar 文件。
-
TestApplication.jar.original − 原始 jar 文件。
Include/Exclude
默认情况下,以下目录及其内容会包含进来。
-
public
-
resources
-
static
-
templates
-
META-INF
默认情况下,以下目录及其内容会排除在外。
-
repository
-
build
-
target
-
*.jar files
-
*.groovy files
使用 --include,我们可以包含原本会被排除的目录。使用 --exclude,我们可以排除原本会被包含的目录。
Running the Executable Jar
键入以下命令
E:/Test/TestApplication/> java -jar TestApplication.jar
您可以在控制台上看到以下输出。
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.6.3)
2022-02-03 11:47:42.298 INFO 8908 --- [ main] .b.c.a.PackagedSpringApplicationLauncher : Starting PackagedSpringApplicationLauncher using Java 11.0.11 on DESKTOP-86KD9FC with PID 8908 (E:\Test\TestApplication\TestApplication.jar started by intel in E:\Test\TestApplication)
2022-02-03 11:47:42.310 INFO 8908 --- [ main] .b.c.a.PackagedSpringApplicationLauncher : No active profile set, falling back to default profiles: default
2022-02-03 11:47:44.839 INFO 8908 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2022-02-03 11:47:44.863 INFO 8908 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2022-02-03 11:47:44.864 INFO 8908 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.56]
2022-02-03 11:47:44.958 INFO 8908 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2022-02-03 11:47:44.959 INFO 8908 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1943 ms
2022-02-03 11:47:45.592 INFO 8908 --- [ main] o.s.b.a.w.s.WelcomePageHandlerMapping : Adding welcome page: class path resource [static/index.html]
2022-02-03 11:47:46.492 INFO 8908 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2022-02-03 11:47:46.514 INFO 8908 --- [ main] .b.c.a.PackagedSpringApplicationLauncher : Started PackagedSpringApplicationLauncher in 5.295 seconds (JVM running for 6.089)