Simple Steps to Run a Spring Boot Application from the Command Line ๐Ÿ–ฅ๏ธ

Spring boot command line tutorial
Photo by Lucas Ludwig / Unsplash

Hello Java developers.

To continue with the Basics here's a practical guide on running Spring Boot applications from the command line. It's a straightforward process, essential for efficient testing and deployment.

So, how to run a spring boot appplication from the command line you may ask ?

What You Need

Before starting, make sure you have:

  • Java Development Kit (JDK): Spring Boot 2.x requires JDK 8 or later, and Spring Boot 3.x needs JDK 17 or later.
  • Maven or Gradle: Your build tool for managing project dependencies.
  • A Spring Boot Application: If you don't have one, create one quickly via Spring Initializr.

Running Your Application in Two Steps

Step 1: Build It

Open your command line in the project directory and run:

For Maven:

mvn clean install

For Gradle

gradle build

This command compiles and packages your code into a JAR file.

You'll find this JAR in the target directory for Maven or build/libs for Gradle.

Step 2: Run It

Now, just execute:

For Maven:

java -jar target/your-app-name.jar

For Gradle:

java -jar build/libs/your-app-name.jar

Replace your-app-name.jar with your actual JAR file name. And that's it!

Good to know

  • Spring Boot CLI: For those who prefer a dedicated tool, Spring Boot CLI is your friend. It lets you run Spring scripts easily.
  • Externalized Configuration: Customize your application's behavior for different environments using command-line properties.

Happy Coding ๐Ÿงก