2
votes

I am new to Spring MVC and I have now come accross tutorials that explain how to deploy your web project as a .jar. My IDE is the Spring Tool Suite. I have always used .war + Apache Tomcat.

Can someone elaborate a bit from the practical point of view why to use .jar instead of .war? Any problems to be aware of?

edit: other answers are welcome too

2

2 Answers

2
votes

Spring Boot uses fat JAR packaging where is embeds Servlet container with all dependencies into this single JAR.

If you are using Maven, it uses spring-boot-maven-plugin to package the project.

Practical usage of this approach is simple. Ability to easily run Srvlet based Spring application from command line with externalized properties. Such configuration enables powerfully orchestration possibilities which are often used in modern enterprises in so called Microservices or SOA architecture.

There is group of people out there (including myself) which believe that deploying various WAR files of unrelated applications into single Servlet runtime is not very good idea.

So fat JARs are handy for separate Servlet runtime per application deployment.

2
votes

About having .jar and Tomcat + .war on the same machine, it is possible and I use this. This may be not cool but I had a .war application running in a tomcat server before the rise up of spring boot. Now my new apps are spring boot apps, and we are migrating our architecture to SOA concept, but we can't change the tire with the moving car. The main application, the WAR is running in a tomcat server and the others (.jar) are self contained ( embedded tomcat ), each one running in a different port. It was the most viable solution available for us by the moment.