java Manifest Main-class 在包含的 jar 库中
java Manifest Main-class in contained jar library
我在使用 java -jar myApp.jar
命令创建可执行文件 jar
时遇到问题。
是否可以制作一个可执行文件 jar
,其中主要 class 位于 myApp.jar
文件中 lib 文件夹中的库之一?
Is it possible to make an executable jar where main class is located in one of the libraries in lib folder within myApp.jar file?
没有
主要 class 需要由标准 JarClassLoader
加载。 classloader 提供 external jar 通过 jar 清单文件中的 Class-Path
条目注册到 classpath 中,但是作为 the Java Tutorial 表示:
Note: The Class-Path
header points to classes or JAR files on the local network, not JAR files within the JAR file or classes accessible over Internet protocols. To load classes in JAR files within a JAR file into the class path, you must write custom code to load those classes. For example, if MyJar.jar
contains another JAR file called MyUtils.jar
, you cannot use the Class-Path
header in MyJar.jar
's manifest to load classes in MyUtils.jar
into the class path.
(强调已添加。)由于您需要自定义代码从 jar 中包含的 jars 加载 classes,并且您需要加载主 class 才能调用任何此类代码,主要 class 本身无法从内部 jar 加载。
然而,可以想象,您可以创建一个可以直接加载的小包装器 class,其唯一目的是设置所需的自定义 classloader 和 bootstrap真正的主要 class.
我在使用 java -jar myApp.jar
命令创建可执行文件 jar
时遇到问题。
是否可以制作一个可执行文件 jar
,其中主要 class 位于 myApp.jar
文件中 lib 文件夹中的库之一?
Is it possible to make an executable jar where main class is located in one of the libraries in lib folder within myApp.jar file?
没有
主要 class 需要由标准 JarClassLoader
加载。 classloader 提供 external jar 通过 jar 清单文件中的 Class-Path
条目注册到 classpath 中,但是作为 the Java Tutorial 表示:
Note: The
Class-Path
header points to classes or JAR files on the local network, not JAR files within the JAR file or classes accessible over Internet protocols. To load classes in JAR files within a JAR file into the class path, you must write custom code to load those classes. For example, ifMyJar.jar
contains another JAR file calledMyUtils.jar
, you cannot use theClass-Path
header inMyJar.jar
's manifest to load classes inMyUtils.jar
into the class path.
(强调已添加。)由于您需要自定义代码从 jar 中包含的 jars 加载 classes,并且您需要加载主 class 才能调用任何此类代码,主要 class 本身无法从内部 jar 加载。
然而,可以想象,您可以创建一个可以直接加载的小包装器 class,其唯一目的是设置所需的自定义 classloader 和 bootstrap真正的主要 class.