Differences between jar and war in Spring Boot?

I'm about to build my first website in Java with Spring Framework using Spring Boot and it's much easier to build it in jar, but I have a few questions about it.

What are the differences in general?

In jar files the views are under /resources/templates, but in war file it's under /webapp/WEB-INF/.

What are the differences? Can I deploy a jar on an online host?


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.