Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I need to update the manifest in my jar file that I create (export) within Eclipse. I've tried to follow this explanation without success. I'm not quite sure what to specify on the command line. The Oracle web site is not too clear. I then found a post on SO that said to extract the manifest.mf file from the jar archive, update it, and add it back to the jar archive. I've tried that too, and it appears to work, however, at runtime, I get java.io.IOException: invalid manifest format. What is the correct way to update the manifest.mf to add new attributes? An example would be most helpful.

like image 517
rrirower Avatar asked Jan 19 '14 21:01

rrirower


1 Answers

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

like image 54
Abhey Rana Avatar answered Dec 21 '22 22:12

Abhey Rana