Updating jar manifest file - java.io.IOException: invalid manifest format

As manifest file is contained in META-INF subdirectory of jar file under the name MANIFEST.MF .Whenever you create a jar file for command prompt by the command jar cvf Jarfilename FilesToadd Then a default manifest file is created. One can view this file and get an idea of valid Manifestfile. In order to extract manifest file from jar type following command in cmd jar xvf Jarfilename now a META-INF subdirectory will appear in the base directory from here you can view default manifest file. Sometimes while updating manifest file we get java.io.IOException: invalid manifest format.This error comes because of following reasons:

1.You may have not left space between the name and value of any section in manifest file,
like Version:1.1 is inavalid section instead write Version: 1.1 that space between colon and 1.1 really matters a lot.

2.While specifying the main class you might have added .class extension at the end of class name.Simply specify the main class by typing Main-Class: Classname.

3.You may have not added newline at the end of file.You need not to write \n for specifying newline instead just leave the last line of your manifest file blank that will serve the purpose

4.Your text file for manifest must use UTF-8 encoding otherwise you may get into some trouble.

Finally i am providing an example of what a manifest file must look like. Here package is calculator and the main class is Calculator.java

Manifest-Version: 2.1

Created-By: UselessCoder

Package-Name: calculator

Class-Name: calculator.Calculator.java

Main-Class: calculator.Calculator


The links offered by Peter were partially useful. However, I was able to solve this more or less by trial and error. The Oracle docs that explain how to do this need lots of work. They lack a good example of how to proceed. Anyway, for those who run into the same issues, here's what I did. I created a text file (eg. "Manifest.txt") using Notepad that contains the manifest attributes I wanted to add/update. In creating this file, I made sure to add a new line character to the last line by pressing the key on the keyboard. Next, I created a DOS bat file to do the actual modification. Here's what it looked like...

echo Updating manifest permissions...
"C:\Program Files\Java\jdk1.7.0_25\bin\jar" -umf "c:\some folder\Manifest.txt" "C:\some folder\jartoupdate.jar"

The order of the jar arguments as they relate to the actual paths that follow on the command line is important. The links from Peter's reply pointed that part out.