JAR 中包含 JAR 的类路径 [英] Classpath including JAR within a JAR

查看:44
本文介绍了JAR 中包含 JAR 的类路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以指定一个包含另一个 JAR 文件中的 JAR 文件的 Java classpath?

Is it possible to specify a Java classpath that includes a JAR file contained within another JAR file?

推荐答案

如果您正在尝试创建一个包含应用程序及其所需库的 jar,有两种方法(我知道)可以做到这一点.第一个是 One-Jar,它使用特殊的类加载器来允许嵌套 jar.第二个是 UberJar,(或 Shade),它会分解包含的库并将所有类放在顶级 jar 中.

If you're trying to create a single jar that contains your application and its required libraries, there are two ways (that I know of) to do that. The first is One-Jar, which uses a special classloader to allow the nesting of jars. The second is UberJar, (or Shade), which explodes the included libraries and puts all the classes in the top-level jar.

我还应该提到 UberJar 和 Shade 分别是 Maven1 和 Maven2 的插件.如下所述,您还可以使用程序集插件(实际上它更强大,但更难正确配置).

I should also mention that UberJar and Shade are plugins for Maven1 and Maven2 respectively. As mentioned below, you can also use the assembly plugin (which in reality is much more powerful, but much harder to properly configure).

这篇关于JAR 中包含 JAR 的类路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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