简体   繁体   English

Spring Boot包Web应用程序到.jar

[英]Spring Boot package web application to .jar

Why Spring Boot by default packaging web applications as .jar ? 为什么Spring Boot默认将Web应用程序打包为.jar Are there any advantages over .war ? .war有什么优势吗?

Shouldn't be all web applications packed as .war in order to be deployed to real web server ? 不应该将所有Web应用程序打包为.war以便部署到真正的Web服务器?

I thought that .jar files are for desktop applications whereas .war files are for web applications. 我认为.jar文件用于桌面应用程序,而.war文件用于Web应用程序。 since .jar doesn't contain web application components as mentioned here: 因为.jar不包含这里提到的Web应用程序组件:

Java war vs. jar - what is the difference? Java战争与jar - 有什么区别?

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. 您链接到有关WAR与JAR的问题,而Spring引导的JAR确实是一个JAR,它包含的内容多于您通常放在JAR中的内容。 Spring boot comes with an embedded servlet container , inside the JAR itself. Spring引导附带一个嵌入式servlet容器 ,位于JAR本身内部。

So the difference: 差异如此:

  • A JAR: Usually contains resources/libraries/desktop applications/... JAR:通常包含资源/库/桌面应用程序/ ...
  • A WAR: A web application that can be run on a web container WAR:可以 Web容器运行的Web应用程序
  • The Spring boot fat JAR: A web application that runs on its own web container Spring boot fat JAR:在自己的Web容器上运行的Web应用程序

About your question: 关于你的问题:

Shouldn't be all web applications packed as .war in order to be deployed to real web server? 不应该将所有Web应用程序打包为.war以便部署到真正的Web服务器?

If you want to run a web application on an existing servlet container, you have to use a WAR file . 如果要在现有servlet容器上运行Web应用程序,则必须使用WAR文件 But the Spring boot JAR comes with its own servlet container, so you can perfectly run it as well. 但Spring引导JAR带有自己的servlet容器,所以你也可以完美地运行它。

Which of the two you choose is your own choice. 您选择哪两个是您自己的选择。 Even though Josh Long's mantra is "Make JAR, not WAR". 尽管Josh Long的口头禅是“制造JAR,而不是战争”。

By default Spring boot will provide you with embedded Tomcat (in jar). 默认情况下,Spring启动将为您提供嵌入式Tomcat(在jar中)。 Deploying such jar will make you less dependant on the environment and requires less configuration ("out of the box solution"). 部署这样的jar将减少对环境的依赖,并且需要更少的配置(“开箱即用的解决方案”)。

See very similar question and its answers. 看到非常相似的问题及其答案。

I think whole point of springboot is speed of development with minimal configuration. 我认为springboot的重点是开发速度最快,配置最少。 So you may think that they provide out of the box solution , that server(tomcat or jetty ) is embedded in the jar. 因此,您可能认为它们提供了开箱即用的解决方案,该服务器(tomcat或jetty)嵌入在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. 此外,云上的微服务仅在jar中推广嵌入式服务器,因此服务器可以仅针对应用程序进行优化,而无需为小型应用程序设置tomcat服务器。

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 https://docs.spring.io/spring-boot/docs/current/reference/html/howto-traditional-deployment.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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