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

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

+6
source share
4 answers

The links suggested by Peter were partially helpful. However, I was able to solve this more or less through trial and error. Oracle docs explaining how to do this require a lot of work. They do not have a good example of how to act. Anyway, for those facing the same problems, here's what I did. I created a text file (for example, "Manifest.txt") using Notepad, which contains the manifest attributes that I wanted to add / update. When creating this file, I definitely added a new line character to the last line by pressing a key on the keyboard. Then I created a bat DOS file for the actual modification. This is how it looked ...

 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 is important, as they relate to the actual paths that follow on the command line. Links from Peter answered that part of.

+2
source

How the manifest file is contained in the META-INF subdirectory of the jar file named MANIFEST.MF. Each time you create a jar command file for the command line with the jar cvf command Jarfilename FilesToadd , a default manifest file is then created. You can view this file and get an idea of ​​the actual manifest file. To extract the manifest file from the jar type, run the following command in cmd jar xvf Jarfilename now the META-INF subdirectory will appear in the base directory where you can view the default manifest file. Sometimes when updating a manifest file, we get java.io.IOException: invalid manifest format . This error occurs due to the following reasons:

1. Perhaps you did not leave a space between the name and value of any section in the manifest file,
for example Version: 1.1 , instead write Version: 1.1 , that the space between the colon and 1.1 really matters.

2. Until you specify the main class, you could add the .class extension at the end of the class name. Just specify the main class by typing Main-Class: Classname .

3. Perhaps you did not add a new line at the end of the file. You do not need to write \ n to indicate a new line, but simply leave the last line of your manifest file empty, which will serve the purpose

4. Your text file for the manifest should use UTF-8 , otherwise you may run into some problems.

Finally, I provide an example of what the manifest file should look like. Here is the calculator package, 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

+2
source

When modifying the bank circuits, you should look more in this direction:
http://docs.oracle.com/javase/tutorial/deployment/jar/update.html and especially
http://docs.oracle.com/javase/tutorial/deployment/jar/modman.html , which describes the process for updating the manifest.

0
source

To update the manifest in the jar file, you found the answer in the oracle docs. Here is another place to see the answer. Assuming you read access to the directory where the JDK is installed, and documentation was downloaded with it (easy to download documentation, this is for SE7 http://www.oracle.com/technetwork/java/javase/documentation/java-se-7 -doc-download-435117.html ):

  • go to [install_directory] / docs . It has an index.html file.
    β†’ β†’, for example. my for JDK 6 is called C: \ my_TOOLS \ Java_stuff \ jdk_1.6.0_20 \ docs \ index.html

  • Drag index.html to the browser page.

  • This page shows you an overview of the JDK documentation and contains many links to useful information. Jdk 6 In the top line of the Java Language line, click JAR. It takes you to a page summarizing the jartool documentation (with links).
    In the "JAR Tools" section of this page, click the link link to a page for your platform (you may need the "JAR Tool Help Page for Windows").

  • This "JAR tool man page" shows detailed documentation for the jar command. Here you will see an example " jar umf Manifest.txt my_jar.jar ". (Solaris / Linux does not use a "-" in front of arguments such as "umf".


I used it (on Linux) to merge 2 custom manifest files into the default manifest and put it in my jar. I do this in a two-step process, but I would be interested to know the one-step command for this. (Using two m for the jar command causes the second manifest to overwrite the first manifest - not to merge.) (Remember that each manifest file must end with an empty line.)

Manifest.txt contains "Name:" and "Implementation Version:"
Manifest.my_app.txt contains "Main-Class:" and "Class-Path:"
The default ad contains "Manifest Version:" and "Created: by:"

 jar cmf my_app.jar Manifest.txt my_main.class my_utils.class jar umf Manifest.my_app.txt my_app.jar 


After that, my META-INF / MANIFEST.MF contains all the fields from all 3 manifestations. I expected them to be attached to each other, but the fields were mixed. Maybe someone can tell how to order them or just add them. This is the order in which they appear in my current META-INF / MANIFEST.MF .

 Manifest-Version: 1.0 Implementation-Title: my_app Implementation-Version: 1.2.1 Class-Path: ... Name: My App Created-By: 1.6.0_20 (Oracle Corporation) Main-Class: My_App 

I hope some of them are useful to you.

0
source

All Articles