简体   繁体   中英

Spring Boot package web application to .jar

Why Spring Boot by default packaging web applications as .jar ? Are there any advantages over .war ?

Shouldn't be all web applications packed as .war in order to be deployed to real web server ?

I thought that .jar files are for desktop applications whereas .war files are for web applications. since .jar doesn't contain web application components as mentioned here:

Java war vs. jar - what is the difference?

You linked to a question about a WAR vs a JAR, while Spring boot's JAR is indeed a JAR, it contains more than what you usually put inside a JAR. Spring boot comes with an embedded servlet container , inside the JAR itself.

So the difference:

  • A JAR: Usually contains resources/libraries/desktop applications/...
  • A WAR: A web application that can be run on a web container
  • The Spring boot fat JAR: A web application that runs on its own web container

About your question:

Shouldn't be all web applications packed as .war in order to be deployed to real web server?

If you want to run a web application on an existing servlet container, you have to use a WAR file . But the Spring boot JAR comes with its own servlet container, so you can perfectly run it as well.

Which of the two you choose is your own choice. Even though Josh Long's mantra is "Make JAR, not WAR".

By default Spring boot will provide you with embedded Tomcat (in jar). Deploying such jar will make you less dependant on the environment and requires less configuration ("out of the box solution").

See very similar question and its answers.

I think whole point of springboot is speed of development with minimal configuration. So you may think that they provide out of the box solution , that server(tomcat or jetty ) is embedded in the jar.

Also micro-services on cloud are promoting embedded server in jar only so that server can be optimized for application only and there is no need to setup tomcat server for small application.

If you want you can create war of spring boot application
https://docs.spring.io/spring-boot/docs/current/reference/html/howto-traditional-deployment.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM