Spring Boot CLI - Packaging Application



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

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

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

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!
Advertisements