'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 :-)



Solution 1:[1]

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:

Solution 2:[2]

  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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Konstantin Yovkov
Solution 2