Springbootcli 简明教程

Spring Boot CLI - Packaging Application

Spring boot CLI 提供 jar 命令,用于将应用程序打包为 jar 文件。让我们测试 Starter Thymeleaf Project Chapter 中创建的示例项目,以演示 Spring CLI 的打包功能。按照以下步骤打包示例项目。

Package the application

键入以下命令

E:/Test/TestApplication/> spring jar TestApplication.jar *.groovy

Output

现在,您可以在 TestApplication 文件夹中看到两个新创建的文件。

  1. TestApplication.jar − 可执行 jar 文件。

  2. TestApplication.jar.original − 原始 jar 文件。

Include/Exclude

默认情况下,以下目录及其内容会包含进来。

  1. public

  2. resources

  3. static

  4. templates

  5. META-INF

默认情况下,以下目录及其内容会排除在外。

  1. repository

  2. build

  3. target

  4. *.jar files

  5. *.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)

Browse the application in Browser

基于弹簧的休息应用程序现已准备就绪。将 url 打开为“http://localhost:8080/”,您将看到以下输出。

Go to Message

点击消息链接,您将看到以下输出。

Message: Welcome to TutorialsPoint.Com!