Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

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?

like image 767
Aaron Digulla Avatar asked Sep 06 '13 14:09

Aaron Digulla


People also ask

How do I specify multiple JARs in classpath?

In general, to include all of the JARs in a given directory, you can use the wildcard * (not *. jar ). The wildcard only matches JARs, not class files; to get all classes in a directory, just end the classpath entry at the directory name.

How do you modify JAR's manifest file?

To modify the manifest, you must first prepare a text file containing the information you wish to add to the manifest. You then use the Jar tool's m option to add the information in your file to the manifest. Warning: The text file from which you are creating the manifest must end with a new line or carriage return.


1 Answers

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

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:/...

like image 97
Aaron Digulla Avatar answered Oct 02 '22 00:10

Aaron Digulla