部署概念:打包JAR依赖关系,何时&为什么 [英] Deployment Concepts: Packaging JAR Dependencies, When & Why

查看:120
本文介绍了部署概念:打包JAR依赖关系,何时&为什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我对Java EE比较陌生,我很难理解Java部署文件何时,何地以及为何与其依赖关系一起打包。

So I'm relatively new to Java EE and I am having a tough time understanding when, where and why Java deployment files are packaged with their dependencies.

Say我将我的项目构建到 myapp.jar ,这取决于fizz.jar,buzz.jar和JODA( joda-time-2.0.jar )。

Say I build my project into myapp.jar, and it depends on fizz.jar, buzz.jar and JODA (joda-time-2.0.jar).

我听说默认的类加载器没有将jar包装在其他jar中,所以我不得不假设我调用了一个 jar <来自Ant的/ em>任务,然后将调用默认的类加载器,并且在没有这3个依赖项的情况下创建 myapp.jar

I've heard that the default classloader doesn't package jars inside of other jars, so I have to assume that if I called a jar task from Ant, then the default classloader would get invoked and myapp.jar would be created without those 3 dependencies in it.

这是因为心态是在容器或其他系统中部署 main -less jars,它们将在运行时提供它的要求吗?如果没有,那么myapp.jar如何正常运行?

Is this because the mentality is to deploy main-less jars in containers or other systems that will provide its requirements at runtime? If not, then how does myapp.jar ever run correctly?

可执行罐子怎么样?要满足,这些必须 main -less jars不同,因为它们是独立单元,对吧?这意味着他们需要将所有依赖项与它们打包在一起,对吗?

What about executable jars? To met, these must be different than main-less jars, because they are meant to be standalone units, right? That means they would need all of their dependencies packaged with them, right?

最后但并非最不重要的,那些依赖于依赖于罐子的罐子的罐子......等等。 (即,依赖图是巨大的)?

Last but not least, what about jars that depend on jars that depend on jars...etc. (i.e., dependencygraphs that are huge)?

我想所有这些问题可以总结如下:

I guess all of these questions can be summed up as follows:


  1. 非可执行jar背后的想法是,它将以这样的方式运行,它将知道在运行时查找其依赖关系的类路径? (因此不需要与其依赖项一起打包)?

  2. 可执行jar背后的想法是它是一个独立的单元,是否应该使用它的依赖项?

  3. 如果我对上述问题#1的断言是正确的,那么这样的类路径配置是如何进行的?这些设置是否存储在jar中(例如清单中)?否则,JRE如何知道在运行时搜索特定jar依赖项的位置?

这些问题的答案实际上将澄清相当<我已经使用Java基础知识了很多,所以任何输入/帮助都会受到极大的欢迎!谢谢

Answers to these questions will actually clarify quite a lot of hangups I have with Java fundamentals, and so any input/help here will be appreciated enormously! Thanks

推荐答案

罐子不知道其他罐子(除非像Maven这样的工具辅助)。罐子的相互依赖性完全由类加载器解决。我强烈建议关于类加载器的一些想法

Jars do not know about other jars (unless assisted by some tools like Maven). The inter dependency of the jars is purely resolved by the Classloaders. I strongly recommend to have some idea about classloaders.

要解决您的问题,

这是一个非可执行jar背后的想法吗?以这样一种方式运行它将知道在运行时查找其依赖项的类路径? (因此不需要与其依赖项一起打包)?


  • NO。如上所述,它是类加载器,它看起来是类路径和其中提到的jar。这些罐子没有关于其他罐子的任何信息。

可执行jar背后的想法是它是一个独立的单元并应与其依赖项打包?


  • NO。类加载器在执行开始时加载独立的可执行jar。如果需要其他依赖jar,它会查看这些jar的类路径。

如果我对问题#1的断言以上是正确的,这样的类路径配置是如何发生的?这些设置是否存储在jar中(例如清单中)?否则,JRE如何知道在运行时搜索特定jar依赖项的位置?


  • 对于独立jar(可执行jar) ),类加载器在调用应用程序时查找传递的类路径变量或类路径。

  • 对于其他类型的应用程序(WAR,EAR),有预定义的位置/文件夹,其中依赖项应该是放置以便拿起来。这是按规格标准化的。

简而言之,它是拉动所有线程的类加载器。有标准的地方可以找到所有相关的罐子。 此链接很好地描述了独立应用程序和部署中的类加载器(在某些应用程序中)容器)工作。

In a nutshell, it's the classloader which is pulling all the threads. There is standard places where it looks for all the dependent jars. This link nicely describes how the classloaders in standalone application and in a deployed (in some container) works.

这篇关于部署概念:打包JAR依赖关系,何时&amp;为什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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