liveBook · Manning

JAR file

As explained in Spring in Action, Sixth Edition

A JAR file is a Java Archive that packages compiled classes, resources, and metadata for distribution or execution.

A JAR file is a Java Archive. An executable Spring Boot JAR packages an application for running with `java -jar`. The Spring Boot plugin includes dependency libraries on the runtime classpath and writes a manifest that identifies the application's bootstrap class. section 1.2.2

Listing 1.2 The Taco Cloud bootstrap class
package tacos;
 
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
 
@SpringBootApplication                                        #1
public class TacoCloudApplication {
 
  public static void main(String[] args) {
    SpringApplication.run(TacoCloudApplication.class, args);  #2
  }
 
}

The bootstrap class has a `main` method that calls `SpringApplication.run`. The JAR's manifest identifies this class as its main class. section 1.2.2

After initializing a Spring Boot project with JAR packaging:

  • Run `mvnw package` for a Maven build. Find the resulting JAR in `target`; its name comes from the project's artifact ID and version. section 18.2
  • Run `gradlew build` for a Gradle build. Find the JAR in `build/libs`. section 18.2
  • Run the built file with `java -jar`. A web application starts its embedded server and listens on its configured port. section 18.2

Deploying Taco Cloud

A built JAR can be pushed to Cloud Foundry with `cf push tacocloud -p target/tacocloud-0.0.19-SNAPSHOT.jar`. An executable JAR suits a PaaS cloud deployment; a traditional Java application server calls for a WAR instead. section 18.2 section 18.1

How Spring in Action, Sixth Edition covers it

How deep it goes
Shows build, launch, and deployment steps plus bootstrap configuration, without examining archive internals.
Examples
Uses Maven and Gradle build commands, `java -jar`, and a Cloud Foundry push command for Taco Cloud.
What it assumes
Assumes a Spring Boot project initialized with JAR packaging and provides the build and run commands.
What you can do after
Operate/configure it by building a Spring Boot JAR, running it with `java -jar`, or deploying it with `cf push`.
How it connects
Connects the Spring Boot plugin, manifest, runtime classpath, embedded server, WAR files, and Cloud Foundry.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring in Action, Sixth Edition. The section links point to the parts of the book it draws on.