Springbootcli 简明教程
Spring Boot CLI - Packaging Application
Spring boot CLI 提供 jar 命令,用于将应用程序打包为 jar 文件。让我们测试 Starter Thymeleaf Project Chapter 中创建的示例项目,以演示 Spring CLI 的打包功能。按照以下步骤打包示例项目。
Spring boot CLI provides jar command in order to package a application as jar file. Let’s test the sample project created in Starter Thymeleaf Project Chapter to demonstrate the packaging capabilities of Spring CLI. Follow the below mentioned step to package the sample project.
Package the application
键入以下命令
Type the following command
E:/Test/TestApplication/> spring jar TestApplication.jar *.groovy
Output
现在,您可以在 TestApplication 文件夹中看到两个新创建的文件。
Now you can see two new files created in TestApplication folder.
-
TestApplication.jar − An executable jar file.
-
TestApplication.jar.original − Original jar file.
Include/Exclude
默认情况下,以下目录及其内容会包含进来。
By default following directories are included along with their contents.
-
public
-
resources
-
static
-
templates
-
META-INF
默认情况下,以下目录及其内容会排除在外。
By default following directories are excluded along with their contents.
-
repository
-
build
-
target
-
*.jar files
-
*.groovy files
使用 --include,我们可以包含原本会被排除的目录。使用 --exclude,我们可以排除原本会被包含的目录。
Using --include, we can include directories excluded otherwise. Using --exclude, we can exclude directories included otherwise.
Running the Executable Jar
键入以下命令
Type the following command
E:/Test/TestApplication/> java -jar TestApplication.jar
您可以在控制台上看到以下输出。
You can see the following output on console.
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: 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/”,您将看到以下输出。
Our spring based rest application is now ready. Open url as "http://localhost:8080/" and you will see the following output.
Go to Message
点击消息链接,您将看到以下输出。
Click on Message link and you will see the following output.
Message: Welcome to TutorialsPoint.Com!