How can I change manifest file in Java

How i can change class-path in mainfest file.

I have external jar file in folder:

Class-Path: folder/AbsoluteLayout.jar

I want to add my external jar file to my JAR MyProject.jar and change mainfast.. What should I write in mainfestu to link against the library into my jar..

Class-Path: path to my externalJar in MyProject.jar

enter image description here

I hope you understand, thank you :-)

Upvotes: 3

Views: 9111

Answers (2)

skanga
skanga

Reputation: 351

  1. Extract the manifest:

    jar xvf MyProject.jar META-INF/MANIFEST.MF

  2. Edit the manifest

  3. Reinsert the edited manifest:

    jar uvf MyProject.jar META-INF/MANIFEST.MF

If you encounter the manifest issue mentioned below by Pabasara, then try this approach

unzip -o MyProject.jar META-INF/MANIFEST.MF
sed -i "s/.*LOOK_FOR.*/REPLACE_WITH/" META-INF/MANIFEST.MF
zip MyProject.jar META-INF/MANIFEST.MF

Upvotes: 3

Konstantin Yovkov
Konstantin Yovkov

Reputation: 62864

You can do :

jar cfm jar-file manifest-addition input-file(s)
  • The c option indicates that you want to create a JAR file.
  • The m option indicates that you want to merge information from an existing file into the manifest file of the JAR file you're creating.
  • The f option indicates that you want the output to go to a file (the JAR file you're creating) rather than to standard output.
  • manifest-addition is the name (or path and name) of the existing text file whose contents you want to add to the contents of JAR file's manifest.

More info:

Upvotes: 5

Related Questions