How to handle files with spaces in the classpath in MANIFEST.MF?

I am trying to create a JAR with a Class-Path element in MANIFEST.MF . I get class path elements from an external source (Maven in my case). Since the paths are absolute and out of my control, they may contain strange characters, such as spaces.

Since spaces are used to separate elements in the class path, this path does not work:

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

How can I avoid / encode odd characters / spaces in the elements of the classpath in the JAR manifest?

+6
source share
2 answers

The elements in the Class-Path element are URLs, so the usual escaping rules apply (and you should also use slashes):

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

Note. An initial slash is necessary because C not a valid network protocol (for example, http or ftp ). If you were pedantic, this should be file:///C:/...

+8
source

For me, carriage character was the only way to successfully exit withespace on a Windows path:

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

Source: https://habr.com/ru/post/953326/


All Articles