简体   繁体   English

如何理解关于可执行jar的spring boot

[英]how to understand spring boot about executable jar

I'm new to Spring Boot and I saw executable jar about spring-boot. 我是Spring Boot的新手,我看到了关于spring-boot的可执行jar。 it says: 它说:

Executable jars and Java 可执行的jar和Java

Java does not provide any standard way to load nested jar files (ie jar files that are themselves contained within a jar). Java没有提供任何标准方法来加载嵌套的jar文件(即jar文件本身包含在jar中)。 This can be problematic if you are looking to distribute a self-contained application. 如果您要分发自包含的应用程序,这可能会有问题。

To solve this problem, many developers use “uber” jars. 为了解决这个问题,许多开发人员使用“超级”罐子。 An uber jar simply packages all classes, from all jars, into a single archive. 一个超级jar简单地将所有类中的所有类打包成一个存档。 The problem with this approach is that it becomes hard to see which libraries you are actually using in your application. 这种方法的问题在于,很难看到您在应用程序中实际使用的库。 It can also be problematic if the same filename is used (but with different content) in multiple jars. 如果在多个罐子中使用相同的文件名(但具有不同的内容),也可能会有问题。

Spring Boot takes a different approach and allows you to actually nest jars directly. Spring Boot采用不同的方法,允许您直接嵌套jar。

I want to know if uber jars or fat jars has some disadvantages,iewe must redeploy entire uber-jars,may run into trouble about NoSuchMethodError.How is Spring boot executable jar diffent from uber jars. 我想知道如果超级罐子或肥胖罐子有一些缺点,那么必须重新部署整个超级罐子,可能会遇到关于NoSuchMethodError的问题。如何从超级罐子中获取Spring启动可执行罐子。 Since it has many disadvantages why does spring boot still use this type of jar? 由于它有许多缺点,为什么弹簧靴仍然使用这种类型的罐子?

With Spring Boot you use spring-boot-maven-plugin or spring-boot-gradle-plugin, which repackages your JAR with all the dependencies. 使用Spring Boot,您可以使用spring-boot-maven-plugin或spring-boot-gradle-plugin,它可以使用所有依赖项重新打包JAR。 This is called fat JAR. 这叫做胖JAR。 This is different than uber JAR. 这与优步JAR不同。

Spring Boot packaging: JAR archive containing dependencies as JAR. Spring Boot打包:包含JAR依赖关系的JAR存档。 Uber JAR: JAR archive containing compiled class files of all dependencies. Uber JAR:包含所有依赖项的已编译类文件的JAR存档。

So Spring Boot is like WAR with embedded tomcat. 所以Spring Boot就像带有嵌入式tomcat的WAR。 So that you can execute it as JAR. 这样您就可以将其作为JAR执行。 This turns to be most modern approach to host cloud native applications. 这变成了托管云原生应用程序的最现代方法。

You can theoretically get NoSuchMethodError if you are using have transitive dependencies of API incompatible versions, but this problem is present with WAR packaging also. 理论上,如果您使用的是具有API不兼容版本的传递依赖性,则可以获得NoSuchMethodError,但此问题也存在于WAR打包中。

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

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