Spring Boot CLI - Packaging Application


Advertisements


Spring boot CLI provides jar command in order to package a application as jar file. Let us test the sample project created in Starter Thymeleaf Project Chapter to demonstrate the packaging capabilities of Spring CLI.

Follow the steps describe below to package the sample project −

Package the application

To package the application, begin by typing the following command −

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

Output

The command will print the following output −

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

To run the executable Jar, type the following command −

E:/Test/TestApplication/> java -jar TestApplication.jar

The above command will generate the following output on console −

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _> | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v1.5.8.RELEASE)

...
2017-11-08 16:27:28.300  INFO 8360 --- [       runner-0] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
2017-11-08 16:27:28.305  INFO 8360 --- [       runner-0] o.s.boot.SpringApplication               : Started application in 4.203 seconds (JVM running for 38.792)

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