How to start up spring-boot application via command line?
Launch a Spring Boot application directly via:
Maven:
Gradle:
Executing a built JAR:
Remember to swap your-app.jar
with your actual JAR filename. Maven/Gradle need to be installed. If not, the frameworks’ respective wrappers, ./mvnw
or ./gradlew
, are here to save the day!
Getting your house in order
Before cranking up a Spring Boot application, your environment needs a little TLC:
Maven and Gradle folk need these to be installed correctly with bin
directory comfortably added to the environment variables.
Got Maven? Your pom.xml
should have this Spring Boot Maven plugin:
And for Gradle projects, toss in the Spring Boot Gradle plugin into build.gradle
:
Proxies lurking in your project? Add the proxy settings to your Maven settings.xml
. For Gradle fans, adjust your Gradle configurations accordingly.
Finally, remember to get cozy in the directory containing your project's root. Because, where else would the pom.xml
or build.gradle
be?
Launching the application
Target port: Firewall problems are nasty! Be sure your application’s port is not blocked. Default port is 8080
, but feel free to tame it in application.properties
or application.yml
.
Creating a package: Before the java -jar
command, box your code into a JAR file using mvn package
or ./gradlew assemble
.
Troubleshooting tips
Classpath issues: Ensure Application.java
is dressed properly and seated inside the right package and the main
method is ready for a power play:
Directory tantrums: Double-check the directory and file names. Typos are not fun when they creep into your runtime.
Level up your startup game
Arguments inputs: Pass arguments to your application by attaching them after your command:
Using profiles: Taste different application moods using profiles in Spring Boot:
Log explorations: Keep those logs in sight! They share tales of the application's adventures during startup.
Was this article helpful?