Why Can a Spring Boot JAR Run Directly?
Spring Boot packages all dependencies and an embedded web server into a single executable JAR, allowing developers to launch the application with a simple "java -jar" command without external configuration or server deployment.
Executable JAR produced by Spring Boot
Self‑contained JAR
Spring Boot packages all compile‑time and runtime dependencies, including third‑party libraries, into a single JAR. The packaging is driven by Maven or Gradle together with the Spring Boot plugin. Adding the starter dependency causes the plugin to copy every required artifact into the final archive:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>Embedded web server
The built JAR contains an embedded servlet container (Tomcat, Jetty or Undertow). At runtime the container is started from within the application, eliminating the need for an external server deployment.
Main class as entry point
Each application defines a class annotated with @SpringBootApplication and a public static void main(String[] args) method that invokes SpringApplication.run() to bootstrap the Spring context.
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class MySpringBootApplication {
public static void main(String[] args) {
SpringApplication.run(MySpringBootApplication.class, args);
}
}Running the JAR
After mvn package (or the Gradle equivalent) produces my-spring-boot-app.jar, the application starts with a single command:
java -jar my-spring-boot-app.jarThe command launches the embedded server, which by default listens on port 8080, allowing the application to accept HTTP requests immediately.
Spring Boot starters
Starters aggregate commonly used dependencies (e.g., spring-boot-starter-web, spring-boot-starter-data-jpa). Declaring a starter eliminates manual dependency enumeration and configuration, further simplifying project setup.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
java1234
Former senior programmer at a Fortune Global 500 company, dedicated to sharing Java expertise. Visit Feng's site: Java Knowledge Sharing, www.java1234.com
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
