Adding nested jars into the classpath

The Java documentation includes a note about adding nested jars into the classpath.

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.

  • Do these tools work simply by extracting classes from the nested jars and adding the extraction path to the classpath? Or does it take more than simply unzipping the archives?
  • Is there a technical reason for the limitation that the manifest.mf classpath can point to the local file system, but not inside its own archive?

  • 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.

    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).

    If you are using a SecrutiyManager things can get even more complicated with security domains.

    tl;dr It's a limitation largely driven by the ClassLoading API

    链接地址: http://www.djcxy.com/p/65804.html

    上一篇: 如何从JAR内读取文件。 两者都存在于服务器上时

    下一篇: 将嵌套jar添加到类路径中