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 (Java Archive) packages compiled classes, resources, and metadata for distribution or execution. An executable Spring Boot JAR also includes dependency libraries and a manifest identifying the application’s main class. section 1.2.2

For a Spring Boot project initialized with JAR packaging, Maven or Gradle can build the executable archive. Maven places it in target; Gradle places it in build/libs. Run the resulting file with java -jar. section 18.2

Build and run Taco Cloud

The Maven wrapper packages Taco Cloud, then java -jar starts the resulting archive. Its bootstrap class runs the Spring application. For a web application, the JAR starts an embedded server and listens on the configured port, 8080 by default. section 1.2.2 section 18.2

$ ./mvnw package
...
$ java -jar target/taco-cloud-0.0.1-SNAPSHOT.jar

See the Maven package and java -jar commands for Taco Cloud. section 1.2.2

An executable JAR is a production deployment option, including for a Platform as a Service such as Cloud Foundry. For a traditional Java application server, use a WAR instead. A JAR can also be packaged in a Docker container for Docker or Kubernetes. section 18.1 section 18.2

$ cf push tacocloud -p target/tacocloud-0.0.19-SNAPSHOT.jar

See how to push a built JAR to Cloud Foundry with the cf command-line tool. section 18.2

How Spring in Action, Sixth Edition covers it

How deep it goes
Explains build, execution, and deployment steps, including dependencies and the manifest, without detailing the archive’s internal layout.
Examples
Uses Taco Cloud to demonstrate Maven packaging, command-line execution, and a Cloud Foundry push.
What you can do after
Apply it via Maven or Gradle to build an executable JAR, run it, and deploy it to Cloud Foundry.
How it connects
Connects executable JARs to Maven, Gradle, application servers, WAR files, Cloud Foundry, Docker, and Kubernetes.

Also explained in

Compare how 2 books explain JAR file →

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.