简体   繁体   English

Rsrc-Class-Path 和 Class-Path 的区别

[英]Difference between Rsrc-Class-Path and Class-Path

can someone tell me please what are the difference between Rsrc-class-Path and Class-Path sections of a runnable-jar's mannifest file?有人能告诉我 runnable-jar 的 mannifest 文件的Rsrc-class-PathClass-Path部分有什么区别吗?

Now I take them as granted as generated by Eclipse, but I'd like to understand how it works.现在我认为它们是 Eclipse 生成的,但我想了解它是如何工作的。

What I think based on how Eclipse generates code seems that the first is about jars my app needs, the second is always .根据 Eclipse 生成代码的方式,我认为第一个是我的应用程序需要的 jars,第二个总是. . . But I have no clues what folder .但我不知道是什么文件夹. refers to.指的是。

The Class-Path attribute. Class-Path属性。 This is a standard attribute defined by the JAR file specification .这是JAR 文件规范定义的标准属性。 It contains a list of relative URLs for that will be included on the runtime classpath when you run the JAR using java -jar... .它包含一个相对 URL 列表,当您使用java -jar...运行 JAR 时,这些 URL 将包含在运行时类路径中。

This provides a way to add external JARs (and directories) to the runtime classpath.这提供了一种将外部 JARs(和目录)添加到运行时类路径的方法。 The entries must be relative, and are resolved relative to the directory containing the main JAR. (For security reasons...)条目必须是相对的,并且相对于包含主要 JAR 的目录进行解析。(出于安全原因...)

The Rsrc-class-Path attribute is non-standard. Rsrc-class-Path属性是非标准的。 This is used by Eclipse's "jars-in-jar" launcher.这是由 Eclipse 的“jars-in-jar”启动器使用的。 A typical manifest looks like this:典型的清单如下所示:

Manifest-Version: 1.0
Rsrc-Main-Class: com.abc.Master
Main-Class: com.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader
Rsrc-Class-Path: ./ lib/xyz.jar

where com.abc.Master is your apps (real) main class, and lib/xyz.jar is a relative URL for a JAR file that is nested within this JAR. .其中com.abc.Master是您的应用程序(真实)主要 class,而lib/xyz.jar嵌套在此 JAR 中的 JAR 文件的相对 URL You will also see that the JAR contains the ".class" file for JarRsrcLoader .您还将看到 JAR 包含JarRsrcLoader的“.class”文件。 This is what happens with you run java -jar this.JAR arg1 arg2 .这就是您运行java -jar this.JAR arg1 arg2时发生的情况。

  1. The JVM is created JVM 被创建
  2. The JVM jar loader opens the JAR, reads and parses the MANIFEST.MF above. JVM jar loader打开JAR,读取并解析上面的MANIFEST.MF。
  3. It loads the JarRsrcLoader class given by Main-Class /它加载Main-Class / 给出的JarRsrcLoader class
  4. It calls the above classes main method, passing it ["arg1", "arg2"]它调用上面类的main方法,传递给它["arg1", "arg2"]
  5. The JarRsrcLoader examines the manifest, and extracts the Rsrc-Class-Path and Rsrc-Main-Class . JarRsrcLoader检查清单,并提取Rsrc-Class-PathRsrc-Main-Class
  6. Then JarRsrcLoader creates a special classloader that knows how read JARs embedded within the current JAR. The classpath for this classloader is "./" follows by "lib/xyz.jar", where these URLs are resolved within the outer JAR file.然后JarRsrcLoader创建一个特殊的类加载器,它知道如何读取嵌入在当前 JAR 中的 JARs。这个类加载器的类路径是“./”,后跟“lib/xyz.jar”,这些 URL外部 JAR 文件中解析。
  7. Then JarRsrcLoader loads the class com.abc.Master using the special class loader.然后JarRsrcLoader使用特殊的 class 加载程序加载 class com.abc.Master
  8. Then JarRsrcLoader calls the main method for com.abc.Master , passing the same string array containing the arguments.然后JarRsrcLoader调用 com.abc.Master 的main方法,传递包含com.abc.Master的相同字符串数组。
  9. Finally, the application runs.最后,应用程序运行。

In short, Rsrc-Class-Path is an attribute that the JarRsrcLoader class understands, and uses to construct the actual application classpath.简而言之, Rsrc-Class-PathJarRsrcLoader class 理解的一个属性,用于构建实际的应用程序类路径。

In this context, the Class-Path: .在这种情况下, Class-Path: . attribute serves no real purpose.属性没有实际用途。 Everything needed to run JarRsrcLoader will be in the JAR.运行JarRsrcLoader所需的一切都在 JAR 中。


As a final note, the SpringBoot loading mechanism is similar, but it uses a different non-standard attribute for the application's main class, and puts the application's resources (eg JARs) into a particular directory ("/boot-inf") within the main JAR.最后要注意的是,SpringBoot 的加载机制是类似的,但它对应用程序的主 class 使用不同的非标准属性,并将应用程序的资源(例如 JAR)放入特定目录(“/boot-inf”)中主 JAR。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM