简体   繁体   English

Java:将JAR文件添加到另一个Jar文件的类路径中

[英]Java: Adding JAR files to the class path of another Jar file

I have a Jar(suppose jar1) file which needs few other jar files(Present in the same directory suppose myjar1.jar and myjar2.jar and so on) during the runtime. 我有一个Jar(假设jar1)文件,在运行时需要几个其他的jar文件(假设在同一目录中,假设myjar1.jar和myjar2.jar等等)。 I am not able to do that using manifest file. 我无法使用清单文件来执行此操作。 I have added below 我在下面添加了

   Class-Path: myjar1.jar 

and also 并且

      Class-Path: ./*

I am creating the Jar(jar1) in my local and pushing it to the server. 我正在本地创建Jar(jar1),并将其推送到服务器。 During compilation and building the Jar(jar1) I dont know the jars(and I dont need them for compilation) that I have to add to the class path. 在编译和构建Jar(jar1)的过程中,我不知道必须添加到类路径中的jar(并且不需要它们进行编译)。 Once I copy it to the server I want other jars present in that directory to be in the class path of my Jar(jar1). 将其复制到服务器后,我希望该目录中存在的其他jar位于Jar(jar1)的类路径中。

PS I have read almost all the articles about adding the classpath to Jar and I am aware that we cannot add classpath as part of the arguments. PS:我已经阅读了几乎所有有关将类路径添加到Jar中的文章,并且我知道我们不能将类路径添加为参数的一部分。

I have total control of the manifest file while compiling and building the Jar. 在编译和构建Jar时,我可以完全控制清单文件。

You have to include all the dependent JAR files in your manifest file as below. 您必须在清单文件中包含所有相关的JAR文件,如下所示。 Use blank space as a separator. 使用空格作为分隔符。

Class-Path: lib/myjar1.jar lib/myjar2.jar

After building your JAR file, extract the JAR and check whether the manifest file is created properly. 构建JAR文件后,解压缩JAR并检查清单文件是否正确创建。

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

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