Spring Boot Applications can be packaged as JAR and run spring boot application in an embedded server just like any other simple Java applications. Debugging is also easy in a Spring Boot application.
In the last tutorial, we have covered various build tools available for building a spring boot application. We are going to mention these tools in this tutorial to run spring boot application.
Let us go through various ways of running an application in the following sections:
pring Boot Application from IDE
- You can import the existing Projects into an IDE like Eclipse STS or IntelliJ directly.
- Import Steps usually vary based on IDE and build system.
- For example, to import
Mavenproject into STS, go to File Menu and select “Import -> Existing Maven Projects” and follow the instructions.
- Once importing the project is successful, you can run the application as a simple Java Application.
- The step by step process of running an application is already covered in the previous tutorials.
Run Spring Boot Application as a packaged application
- You can package a Spring boot application as a JAR or WAR depending on the requirement. However, the recommendation is to package as JAR so that you can do stand-alone deployments in a Production environment.
- Use the Spring Maven plugin to package the application as a JAR and then, you can run the packaged application as follows:
$ java -jar target/demoapplication-0.0.1-SNAPSHOT.jar
- Debugging the application is also possible if you add the following arguments to the command line:
$ java -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=8000,suspend=n -jar target/myapplication-0.0.1-SNAPSHOT.jar
Run Spring Boot Application using Maven
The Spring Boot Maven Plugin includes a goal named “spring-boot
Follow the below steps to configure the Maven “run” goal :
- Right Click on the Project and Select Run As -> Run Configurations as shown in the following screen capture:
2. Right Click on Maven Build and select “New Configuration“:
3. Then, Select the Project name in the Base directory and enter the goals: “spring-boot:run” and Click on Run Button. Refer the following screenshot:
4. Once Run button is clicked, you should see the following console output, indicating that the application compiled and started up successfully.
Run Spring Boot
appliaction using Gradle
Similar to the run goal for Maven, Gradle Users can make use of a similar task named: “bootRun” to run your application.
- The command usage is as shown in the following:
$ gradle bootRun
To conclude, we have covered the various methods in order to package and run spring boot application using various build tools in this tutorial.
Also, this tutorial is prepared with primary focus on using Maven and STS.
Refer the following links as next steps: