How to start up spring-boot application via command line?
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
Starting a Spring Boot application from the command line is the most direct way to validate builds, run services in CI, and reproduce production startup behavior locally. You can launch either from source using Maven or Gradle, or from a packaged jar using java -jar. A clean command line workflow also makes profile and environment debugging much easier.
Verify Tooling and Project State
Before startup, confirm Java and build tooling versions to avoid hidden environment mismatch.
At project root, verify that one of these files exists:
pom.xmlfor Maven.build.gradleorbuild.gradle.ktsfor Gradle.
Also ensure your main class has @SpringBootApplication and is reachable by package scanning.
Run Directly from Source During Development
Running from source gives fast feedback for code changes.
Maven:
Gradle:
Pass profile and custom properties during startup:
For Gradle:
Use this mode when you need rapid iteration and do not require packaging artifacts.
Package and Run as Executable Jar
For CI and production-like validation, build once and run the artifact.
Maven package:
Gradle package:
Running jar mode helps catch issues related to packaging, classpath, and startup scripts that may not appear in source run mode.
Configure Environment and Secrets Safely
Spring Boot reads configuration from command args, environment variables, and application files. Keep secrets out of shell history when possible.
Example with environment variables:
For one off overrides, pass command line properties:
Prefer externalized config files for repeatable deploys.
Monitor Startup and Verify Health
After launch, inspect logs for profile, port, and datasource messages. Then verify health endpoint if Actuator is enabled.
Check open port when debugging collisions:
If startup hangs, run with debug condition report:
This report is useful for diagnosing auto configuration conflicts.
Run in the Background for Local Service Testing
For integration tests that need the app running in background, use nohup and capture logs.
Stop later:
Keep background process management simple and explicit to avoid orphan processes.
Add JVM Options for Production-Like Runs
When startup behavior differs between environments, run the jar with explicit JVM settings to reduce ambiguity. This is useful for memory diagnostics and reproducible performance tests.
Keep JVM flags in versioned run scripts so team members and CI jobs execute the same runtime profile.
Common Pitfalls
- Running with one Java version locally and another in CI.
- Assuming
bootRunbehavior matches packaged jar behavior exactly. - Hard coding secrets in command history or source files.
- Ignoring profile activation and debugging wrong config values.
- Forgetting to verify startup health before running dependent services.
Summary
- Use
spring-boot:runorbootRunfor fast source based development. - Use packaged jar startup to validate production like runtime behavior.
- Pass profiles and properties explicitly to avoid configuration ambiguity.
- Verify startup through logs, port checks, and health endpoints.
- Keep process and secret management disciplined for reliable CLI workflows.
- Keep JVM options documented for reproducible operations.
Related reading
- How to stop a thread created by implementing runnable interface?
- How to store printStackTrace into a string
- How To Stream Chunked Response With Spring Boot RestController
- How to subtract X day from a Date object in Java?
- How to subtract X days from a date using Java calendar?
- How to supply value to an annotation from a Constant java
- How to synchronize a static variable among threads running different instances of a class in Java?
- How to tell a Mockito mock object to return something different the next time it is called?

OOD Fundamentals
Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.