Spring Boot CLI Commands

The Spring Boot CLI is a powerful tool to create/manage your projects. By executing the command with the ‘–help’ parameter, you will see the list of available options:

./spring --help
usage: spring [--help] [--version]
       <command> [<args>]

Available commands are:

  run [options] <files> [--] [args]
    Run a spring groovy script

  grab                
    Download a spring groovy script's dependencies to ./repository

  jar [options] <jar-name> <files>
    Create a self-contained executable jar file from a Spring Groovy script

  war [options] <war-name> <files>
    Create a self-contained executable war file from a Spring Groovy script

  install [options] <coordinates>
    Install dependencies to the lib/ext directory

  uninstall [options] <coordinates>
    Uninstall dependencies from the lib/ext directory

  init [options] [location]
    Initialize a new project using Spring Initializr (start.spring.io)

  encodepassword [options] <password to encode>
    Encode a password for use with Spring Security

  shell                
    Start a nested shell

Let’s see a bit more in detail each command.

The run Command

The run command will allow you to run Java or Groovy Spring Boot applications. Here is a sample usage of it which starts an application named “myapp.groovy” overriding the default Web Server Port:

$ spring run myapp.groovy -- --server.port=8081

If you have several files, you can use the wildcard * to compile all of them. Just execute this command:

$ spring run *.groovy

The test Command

The test command runs a Spring Groovy script and Java tests. To run it, you execute:

$ spring test test.groovy

The grab Command

The grab command will download all the Spring Groovy scripts and Java dependencies to the ./repository
directory. Example:

$ spring grab MyApplication.java

The jar Command

The jar command will create a self- contained executable JAR file from a Groovy or Java script. Example:

$ spring jar myapp.jar app.groovy

The resulting app.jar is a fat JAR that can be executed with the following:

$ java -jar myapp.jar

The war Command

This is very similar to the previous command. The war command will create a self-contained executable
WAR file from a Groovy or Java script. Example:

$ spring war app.war app.groovy

The install Command

The install command is very similar to the grab command; the only difference is that you need to specify the library you want to install (in a coordinate format groupId:artifactId:version ; the same as the @Grab annotation). It will download it and the dependencies in a lib directory. Example:

$ spring install org.spockframework:spock-core:1.0-groovy-2.4

You will have in the lib directory the Spock library and its dependencies.

The uninstall Command

The uninstall command will uninstall the dependencies from the lib directory. You can test this command by executing the following command:

$ spring uninstall org.spockframework:spock-core:1.0-groovy-2.4

The init Command

The init command will help you initialize a new project by using the Spring Initializr ( http://start.spring.io/ ). Whether or not you are using an IDE, this command will help you get everything ready to start developing Spring Boot applications. Check out this tutorial to learn more about using Spring init to boostrap your projects: Using Spring boot CLI to bootstrap your projects

 

Found the article helpful? if so please follow us on Socials
Twitter Icon       Facebook Icon       LinkedIn Icon       Mastodon Icon