什么是带阴影的罐子?超级罐子和阴影罐子之间的区别/相似之处是什么? [英] What is a shaded jar? And what is the difference/similarities between uber jar and shaded jar?

查看:231
本文介绍了什么是带阴影的罐子?超级罐子和阴影罐子之间的区别/相似之处是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您能帮忙解释一下什么是带阴影的罐子,以及maven-shade-plugin有什么用吗?还有什么是超级罐子.

Can you please help explain what is a shaded jar and how is the maven-shade-plugin useful? Also what is an uber jar.

推荐答案

我将首先解释什么是超级JAR,因为这支持了阴影说明.

I'll explain what an uber JAR is first because this underpins the shading explanation.

Uber JAR

超级JAR是包含多个JAR(或更常见的是,其他多个JAR本身)内容的JAR

An uber JAR is a JAR which contains the contents of multiple JARs (or, less commonly, multiple other JARs themselves)

您的应用程序几乎可以肯定会使用其他软件包,并且这些软件包可能以JAR的形式提供.使用Maven时,这些依赖关系表示如下:

Your application will almost certainly use other packages and these packages might be provided as JARs. When using Maven these dependencies would be expressed as follows:

<dependency>
    <groupId>...</groupId>
    <artifactId>...</artifactId>
    <version>...</version>
</dependency>

在运行时,您的应用程序将期望在其类路径中找到此JAR中包含的类.

At runtime your application will expect to find the classes contained in this JAR on its classpath.

您可以创建一个包含所有这些依赖JAR的所有类等的uber JAR,而不是将每个依赖JAR与您的应用程序一起交付,然后从该uber JAR中运行您的应用程序.

Rather than shipping each of these dependent JARs along with your application, you could create an uber JAR which contains all of the classes etc from these dependent JARs and then simply run your application from this uber JAR.

底纹

着色提供了一种创建uber JAR并重命名uber JAR包含的包的方法.如果您的uber JAR可能被用作另一个应用程序中的依赖项,则存在uber JAR中的依赖类版本可能与该另一个应用程序中的相同依赖项版本冲突的风险.通过在uber JAR中重命名软件包,阴影有助于避免任何此类问题.

Shading provides a way of creating an uber JAR and renaming the packages which that uber JAR contains. If your uber JAR is likely to be used as a dependency in another application then there's a risk that the versions of the dependent classes in the uber JAR might clash with versions of those same dependencies in this other application. Shading helps to avoid any such issue by renaming the packages within the uber JAR.

例如:

  1. 您创建一个uber JAR,其中包含Foo库的v1.0.0.
  2. 其他人在其应用程序Bar
  3. 中使用您的超级JAR
  4. Bar应用程序对Foo有自己的依赖性,但对该库的v1.2.0有依赖性.
  1. You create an uber JAR which contains v1.0.0 of the Foo library.
  2. Someone else uses your uber JAR in their application, Bar
  3. The Bar application has its own dependency on Foo but on v1.2.0 of that library.

现在,如果Foo的1.0.0版和1.2.0版之间存在冲突,我们可能会遇到问题,因为Bar的所有者无法依赖将加载哪一个,因此它们的代码将无法正常运行或您的代码-在其应用程序中运行时-行为不当.

Now, if there is any clash between versions 1.0.0 and 1.2.0 of Foo we may have a problem because the owner of Bar cannot rely on which one will be loaded so either their code will misbehave or your code - when running within their application - will misbehave.

着色有助于避免诸如此类的问题,并且还允许Foo的提供者明确说明其使用的依赖库的版本.

Shading helps to avoid issues such as this and also allows the provider of Foo to be explicit about the versions of the dependent libraries it uses.

通过maven-shade-plugin,您可以(a)创建超级JAR,并(b)对其内容进行着色.

The maven-shade-plugin allows you to (a) create an uber JAR and (b) to shade its contents.

摘要

创建超级JAR是简化部署过程的有用技术.

Creating an uber JAR is a useful technique for simplifying your deployment process.

阴影是对超级JAR概念的扩展,通常仅限于

Shading is an extension to the uber JAR idea which is typically limited to use cases where

  • JAR是要在另一个应用程序/库中使用的库
  • JAR的作者希望确保JAR所使用的依赖项在他们的控制之内
  • JAR的作者希望避免任何使用JAR的应用程序/库的版本冲突"问题

这篇关于什么是带阴影的罐子?超级罐子和阴影罐子之间的区别/相似之处是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆