简体   繁体   English

Jar依赖项编译时间和运行时

[英]Jar dependencies compile time and runtime

If by default, when I produce a jar application, the dependencies are not include, does that mean that the user should download all the dependencies of my app to use it? 如果默认情况下,当我生成jar应用程序时,不包括依赖项,这是否意味着用户应下载应用程序的所有依赖项以使用它?

Why includes dependencies in jar is not the default thing? 为什么在jar中包含依赖项不是默认设置?

How can I expect users to have/download all the dependencies at with the exact version needed? 我如何期望用户以所需的确切版本拥有/下载所有依赖项?

From https://imagej.net/Uber-JAR : https://imagej.net/Uber-JAR

Advantages : 优点

A single JAR file is simpler to deploy. 单个JAR文件更易于部署。 There is no chance of mismatched versions of multiple JAR files. 多个JAR文件的版本不匹配的可能性不大。 It is easier to construct a Java classpath, since only a single JAR needs to be included. 构造Java类路径比较容易,因为只需要包含一个JAR。

Disadvantages : 缺点

Every time you need to update the version of the software, you must redeploy the entire uber-JAR (eg, ImageJ is ~68 MB as of May 2015). 每次需要更新软件版本时,都必须重新部署整个uber-JAR(例如,截至2015年5月,ImageJ为〜68 MB)。 If you bundle individual JAR components, you need only update those that changed. 如果捆绑了单个JAR组件,则只需更新已更改的组件。 This issue is of particular relevance to Java applications deployed via Java Web Start, since it automatically downloads the latest available version of each JAR dependency; 这个问题与通过Java Web Start部署的Java应用程序特别相关,因为它会自动下载每个JAR依赖项的最新可用版本; in that case, your application startup time will suffer if you use the uber-JAR. 在这种情况下,如果使用uber-JAR,您的应用程序启动时间将受到影响。

You cannot cherry-pick only the JARs containing the functionality you need, so your application's footprint may suffer from bloat. 您不能只挑选包含所需功能的JAR,因此应用程序的内存可能会膨胀。

If downstream code relies on any of the same dependencies which are embedded in an unshaded uber-jar, you may run into trouble (eg, NoSuchMethodError for unshaded uber-JARs) with multiple copies of those dependencies on your classpath, especially if you need to use a different version of that dependency than is bundled with the uber-JAR. 如果下游代码依赖于无阴影的uber-jar中嵌入的任何相同依赖项,则可能会在类路径上拥有这些依赖项的多个副本(例如,无阴影的uber-JAR出现NoSuchMethodError),尤其是在您需要使用与uber-JAR捆绑在一起的版本不同的依赖关系。

As you can see, it is important to understand how use of the uber-JAR will affect your application. 如您所见,了解uber-JAR的使用将如何影响您的应用程序非常重要。 In particular, Java applications will likely be better served using the individual component JARs, ideally managed using a dependency management platform such as Maven or Ivy. 特别是,使用单个组件JAR可以更好地服务Java应用程序,最好使用依赖关系管理平台(例如Maven或Ivy)对其进行管理。 But for non-Java applications, the uber-JAR may be sufficient to your needs. 但是对于非Java应用程序,uber-JAR可能足以满足您的需求。

It basically depends on the use case. 它基本上取决于用例。 If the jar will be used in development of other applications and its dependencies might be updated time to time, it makes sense to use a normal jar, but if the jar is to be run/deployed, it might be better to use an uber/fat jar. 如果将jar用于其他应用程序的开发中,并且其依赖关系可能会不时更新,则可以使用普通的jar,但是如果要运行/部署jar,则最好使用uber /胖子

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

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