jar清单中的绝对路径名与相对路径名 [英] absolute versus relative path names in jar manifest

查看:197
本文介绍了jar清单中的绝对路径名与相对路径名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在固定位置引用一个jar文件,供多个可执行jar使用,而不是在每个可执行文件中包含该jar。我有以下设置工作正常

I want to reference a jar file in fixed location for use by multiple executable jars rather than include that jar in each of the executables. I have the following setup which works fine

commons-math3-3.6.1.jar存在于目录testgradle中。 TestGradle.jar包含main方法并存在于testgradle / build / libs目录中

commons-math3-3.6.1.jar exists in directory testgradle. TestGradle.jar contains the main method and exists in directory testgradle/build/libs

来自testgradle / build / libs我运行:

from testgradle/build/libs I run:

java -jar TestGradle.jar

事情很好。 TestGradle.jar中的清单包含:

And things work fine. The manifest in TestGradle.jar contains:

Manifest-Version: 1.0
Class-Path: ../../commons-math3-3.6.1.jar
Main-Class: com.spgxyz.test.testg

但我想用绝对路径来处理commons-math3-3.6.1.jar,以便TestGradle.jar之类的可执行jar可以从它们所在的目录中使用它。但是,如果我更改了TestGradle.jar清单包括完整路径:

But I want to address commons-math3-3.6.1.jar with an absolute path so that executable jars such as TestGradle.jar can use it from whichever directory they reside in. However, if I change TestGradle.jar manifest to include the full path:

Manifest-Version: 1.0
Class-Path: C:\Users\Admin\workspace\TestGradle\commons-math3-3.6.1.ja
 r
Main-Class: com.spgxyz.test.testg

然后命令:

java -jar TestGradle.jar

从testgradle / build / libs运行产生:

run from testgradle/build/libs produces:

Error: Could not find or load main class com.spgxyz.test.testg
Caused by: java.lang.ClassNotFoundException: com.spgxyz.test.testg

我尝试对清单进行各种编辑以尝试解决此问题,例如:

I tried various edits to the manifest to try to cure this such as:

Manifest-Version: 1.0
Class-Path: . C:\Users\Admin\workspace\TestGradle\commons-math3-3.6.1.
 jar
Main-Class: com.spgxyz.test.testg

Manifest-Version: 1.0
Class-Path: TestGradle.jar C:\Users\Admin\workspace\TestGradle\commons
 -math3-3.6.1.jar
Main-Class: com.spgxyz.test.testg

这两者都会产生相同的错误。如果有人能够对这里发生的事情有所了解,我将非常感激。在Windows上运行。

These both produce the same error. If someone could shed some light on what's going on here I'd be very grateful. Running on windows.

推荐答案

Class-Path 属性被解释为URL列表,因此,要使用绝对路径(在此处用URL表示),它应该以schema开头并使用正斜杠。

Class-Path attribute is interpreted as a list of URLs, so, to use an absolute path (represented with a URL here), it should start with schema and use forward slashes.

请尝试以下操作:

Class-Path: file:///C:/Users/Admin/workspace/TestGradle/commons-math3-3.6.1.jar

这篇关于jar清单中的绝对路径名与相对路径名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆