Run a spring boot project from command line

Some points here to know for if you run your spring boot project using the command line

  1. During Development we spend most of our time in the IDE IntellIj,eclipse,Netbeans
  2. However, We may want to run our Spring Boot App outside of the IDE
  3. One approach is running from the command-line
  4. When running from the command -line
  5. No need to have IDE open / running
  6. Since we using Spring Boot, the server is embedded in our JAR File
  7. No need to have separate server installed /running
  8. Spring boot apps are self-contained server all ready

Using Two way to running your application using Command Line(CMD)

  1. Way 1: Use java -jar (java -jar app.jar)
  2. Way 2: Use Spring Boot Maven Plugin (mvnw spring-boot:run)

Development Process for the Command-Line to run our project

  1. Exit the IDE
  2. Package the app using mvnw package
  3. Run app using java -jar
  4. Run app using Spring boot Maven plugin ,mvnw spring-boot:run
Using First Way

step 1 : Go to workspace project directory and write mvnw package

C:\Users\xyz\Documents\workspace\commandline-demo>mvnw package

step 2 :It creates the JAR file for our application in the project target directory. JAR is created in the target directory and go to the target subdirectory

C:\Users\xyz\Documents\workspace\commandline-demo> cd target

C:\Users\xyz\Documents\workspace\commandline-demo>java -jar demowithtool-0.0.1-SNAPSHOT.jar

NOTE : Stop our Spring Boot app with CTRL+C

Using Second Way

If you want Run your application using Spring Boot Maven Plugin then write on cmd mvnw spring-boot:run

\Users\xyz\Documents\workspace\commandline-demo>mvnw spring-boot:run