如何处理MANIFEST.MF中类路径中带空格的文件?

时间:2021-01-30 06:28:34

I try to build JAR with a Class-Path element in the MANIFEST.MF. I get the elements of the class path from an outside source (Maven in my case). Since the paths are absolute and beyond my control, they can contain weird characters like spaces.

我尝试在MANIFEST.MF中使用Class-Path元素构建JAR。我从外部源(我的情况下是Maven)获取类路径的元素。由于路径是绝对的并且超出我的控制范围,因此它们可以包含奇怪的字符,如空格。

Since spaces are used to separate items in the class path, this path doesn't work:

由于空格用于分隔类路径中的项目,因此该路径不起作用:

Class-Path: C:\User\Some Odd Name\project\target\project-1.0.0.jar

How can I escape / encode odd characters / whitespace in items of the classpath in the JAR Manifest?

如何在JAR Manifest中的类路径项中转义/编码奇数字符/空格?

2 个解决方案

#1


9  

Elements in the Class-Path element are URLs, so the usual escaping rules apply (and you should use forward slashes as well):

Class-Path元素中的元素是URL,因此通常的转义规则适用(并且您也应该使用正斜杠):

Class-Path: /C:/User/Some%20Odd%20Name/project/target/project-1.0.0.jar

Note: The initial slash is necessary since C is not a valid network protocol (like http or ftp). If you were pedantic, it should be file:///C:/...

注意:由于C不是有效的网络协议(如http或ftp),因此必须使用初始斜杠。如果你是迂腐的,那应该是file:/// C:/ ...

#2


-1  

For me the caret character was the only way to successfully escape the withespace in a Windows classpath:

对我来说,插入字符是成功转义Windows类路径中的withespace的唯一方法:

Class-Path: C:\User\Some^ Odd^ Name\project\target\project-1.0.0.jar

#1


9  

Elements in the Class-Path element are URLs, so the usual escaping rules apply (and you should use forward slashes as well):

Class-Path元素中的元素是URL,因此通常的转义规则适用(并且您也应该使用正斜杠):

Class-Path: /C:/User/Some%20Odd%20Name/project/target/project-1.0.0.jar

Note: The initial slash is necessary since C is not a valid network protocol (like http or ftp). If you were pedantic, it should be file:///C:/...

注意:由于C不是有效的网络协议(如http或ftp),因此必须使用初始斜杠。如果你是迂腐的,那应该是file:/// C:/ ...

#2


-1  

For me the caret character was the only way to successfully escape the withespace in a Windows classpath:

对我来说,插入字符是成功转义Windows类路径中的withespace的唯一方法:

Class-Path: C:\User\Some^ Odd^ Name\project\target\project-1.0.0.jar