Spring Boot package web application to .jar

后端 未结 3 1246
孤街浪徒
孤街浪徒 2021-02-13 15:11

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 i

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-13 15:49

    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".

提交回复
热议问题