将嵌套罐子添加到类路径中 [英] Adding nested jars into the classpath
问题描述
Java 文档包含有关添加嵌套的注释进入类路径.
The Java documentation includes a note about adding nested jars into the classpath.
要将JAR文件中JAR文件中的类加载到类路径中, 您必须编写自定义代码才能加载这些类.
To load classes in JAR files within a JAR file into the class path, you must write custom code to load those classes.
有许多工具可以执行此操作,例如 和此处.
There are many tools that do this, such as the ones listed here and here.
- 通过从嵌套jar中提取类并将提取路径添加到类路径中,这些工具是否简单起作用?还是只需要解压缩存档即可?
- manifest.mf类路径可以指向本地文件系统,但不能指向其自己的归档文件,是否存在限制的技术原因?
推荐答案
Another option if you are using Maven is the Shade Mojo. It will explode all of the JARs, allowing their contents to be packaged with your code. It is also capable of other magic, like moving dependencies into custom packages to avoid conflicts and merging files found in META-INF.
一个主要的问题是,通常JAR会在完全相同的位置公开工件.对于允许通过 ServiceLoader .这些文件需要智能地合并/串联.
One of the primary problems with this is that often JARs will expose artifacts at exactly the same location. This can be problematic for (usually JDK) systems that allow extension via ServiceLoader. These files need to be intelligently merged / concatenated.
Another API that could be effected in subtle, possible bug causing ways, is ClassLoader.getResources(String).
如果您使用的是SecrutiyManager
,则使用安全域会使事情变得更加复杂.
If you are using a SecrutiyManager
things can get even more complicated with security domains.
tl; dr 这是一个主要由ClassLoading API驱动的限制
tl;dr It's a limitation largely driven by the ClassLoading API
这篇关于将嵌套罐子添加到类路径中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!