This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Manifest problem in creating a jar file (CLI) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Manifest problem in creating a jar file (CLI)" Watch "Manifest problem in creating a jar file (CLI)" New topic
Author

Manifest problem in creating a jar file (CLI)

Jon Camilleri
Ranch Hand

Joined: Apr 25, 2008
Posts: 660

Any idea what is wrong with this manifest file please? I'm using WinXP command line. The first line is stated to be the minimum legal manifest by Horstmann and Cornell.



Manifest-Version: 1.0
Name:FileChooserTest.class
Loads a JFileChooser

Command line
>jar cfm FileChooser.jar JFileChooser.mf *.class
java.io.IOException: invalid header field
at java.util.jar.Attributes.read(Attributes.java:393)
at java.util.jar.Manifest.read(Manifest.java:182)
at java.util.jar.Manifest.<init>(Manifest.java:52)
at sun.tools.jar.Main.run(Main.java:132)
at sun.tools.jar.Main.main(Main.java:1022)

>
>
>type *.mf

JFileChooser.mf


Manifest-version: 1.0
Name:FileChooserTest.class
Loads a JFileChooser

>jar cfm FileChooser.jar JFileChooser.mf *.class
java.io.IOException: invalid header field
at java.util.jar.Attributes.read(Attributes.java:393)
at java.util.jar.Manifest.read(Manifest.java:182)
at java.util.jar.Manifest.<init>(Manifest.java:52)
at sun.tools.jar.Main.run(Main.java:132)
at sun.tools.jar.Main.main(Main.java:1022)

>


Jon
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14118
    
  17

You specify the entry point of the program (the main class) with a Main-Class attribute (not a Name attribute). I'm not sure if Name is a valid attribute in a manifest file.

Also, put a space between the : and the value of the attribute. Make sure that the manifest ends with an empty line; there's a known problem where Java will not read the last line of the manifest file if it doesn't end with an empty line.

See Working with Manifest Files in Oracle's Java Tutorials for details on how to use manifest files.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19685
    
  20

And don't forget that class names never end with ".class".


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Jon Camilleri
Ranch Hand

Joined: Apr 25, 2008
Posts: 660

Jesper de Jong wrote:You specify the entry point of the program (the main class) with a Main-Class attribute (not a Name attribute). I'm not sure if Name is a valid attribute in a manifest file.

Also, put a space between the : and the value of the attribute. Make sure that the manifest ends with an empty line; there's a known problem where Java will not read the last line of the manifest file if it doesn't end with an empty line.

See Working with Manifest Files in Oracle's Java Tutorials for details on how to use manifest files.


In the meantime I have compiled my first minimalist version of the manifest file with the following command line and manifest file; what tool do I need to create a SHA-5 signature?

Microsoft Windows XP [Version 5.1.2600]
>jar cfm FileChooser.jar JFileChooser.mf *.class
>type JFileChooser.mf
Manifest-Version: 1.0
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14118
    
  17

I guess you want to do that because you want to digitally sign your JAR file? The tutorial explains that in detail in this part: Signing and Verifying JAR Files.

Normally it's not required to sign your JAR file. You only need to do that for applets for example, if the applet needs special privileges which go beyond what the normal applet sandbox runtime environment allows applets to do.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Manifest problem in creating a jar file (CLI)