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?
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.
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.
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:/...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With