Differences between jar and war in Spring Boot?
Spring Boot can be told to produce a 'fat JAR' which includes all of your module/service's dependencies and can be run with java -jar <your jar>
. See "Create an executable JAR with Maven" here.
Spring Boot can also be told to produce a WAR file, in which case you'll likely choose to deploy it to a web container such as Tomcat or Jetty.
Plenty more details on Spring Boot deployment here.
Depends on your deployment. If you are planning to deploy your application to an existing Java EE Application Server (e.g. Tomcat), then standard approach is to perform a war
build.
When you use fat jar approach, your application will be deployed on embedded application container provided by spring boot. Conduct Deploying Spring Boot Applications for more information.
Running spring-boot
application as fat *.jar
It is possible to build so called fat JAR
that is executable *.jar
file with embedded application container (Tomcat
as default option).There are spring-boot
plugins for various build systems. Here is the one for maven
: spring-boot-maven-plugin
To execute the kind of fat
*.jar
you could simple run command:
java -jar *.jar
Or using spring-boot-maven
goal:
mvn spring-boot:run
Building spring-boot
application as *.war
archive
The other option is to ship your application as old-fashioned war
file. It could be deployed to any servlet container out there. Here is step by step how-to list:
- Change
packaging
towar
(talking about maven'spom.xml
) - Inherit main
spring-boot
application class fromSpringBootServletInitializer
and overrideSpringApplicationBuilder configure(SpringApplicationBuilder)
method (see javadoc) - Make sure to set the
scope
ofspring-boot-starter-tomcat
asprovided