Differences between jar and war in Spring Boot?

Viewed 55749

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?

7 Answers

I was under the same problem, when I deployed my jar issue free on my local. Then I had to demo it on the server. You can create a war file by changing the pom.xml , tag

<packaging>jar</packaging>

to

<packaging>war</packaging>

and you will have a war file in your target which you can deploy to your server(tomcat in my case)

If you need to deploy it in an external container, you'll normally have to create a war file (which doesn't have to be executable).

If you want to use the embedded container, you can choose to create an executable .jar file or an executable .war file. AFAIK the only difference is in the layout of the archive, and therefore normally also the layout of your source repository.

E.g. using standard folder structure with Maven / Gradle, static resources for a .jar will need to be in src/main/resources/static while for a .war file they should be in src/main/webapp.

war file is a Web Application Archive which runs inside an application server while a .jar is Java Application Archive that runs a desktop application on a user's machine. A war file is a special jar file that is used to package a web application to make it easy to deploy it on an application server.

Simple and easy answer. Packaging type jar represented as standalone application and packaging type war represented as web application.

Related