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
- During Development we spend most of our time in the IDE IntellIj,eclipse,Netbeans
- However, We may want to run our Spring Boot App outside of the IDE
- One approach is running from the command-line
- When running from the command -line
- No need to have IDE open / running
- Since we using Spring Boot, the server is embedded in our JAR File
- No need to have separate server installed /running
- Spring boot apps are self-contained server all ready
Using Two way to running your application using Command Line(CMD)
- Way 1: Use java -jar (java -jar app.jar)
- Way 2: Use Spring Boot Maven Plugin (mvnw spring-boot:run)
Development Process for the Command-Line to run our project
- Exit the IDE
- Package the app using mvnw package
- Run app using java -jar
- 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