This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes Updating a JAR manifest Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Updating a JAR manifest" Watch "Updating a JAR manifest" New topic
Author

Updating a JAR manifest

Neil Laurance
Ranch Hand

Joined: Jul 18, 2002
Posts: 183
I am playing around with creating a stand-alone JAR file, to be run like:
java -jar hello.jar
My jar file only contains:

Where the manifest was created automatically using:
$ jar cvf hello.jar com/neil/Hello.class
Now, running like:
$ java -cp hello.jar com.nkl.Hello works
But, I tried extracting the MANIFEST.MF file, and adding:
Main-Class: com.neil.Hello
Tyring to overwrite the MANIFEST.MF back into the jar file doesn't seem to work. The error I get is:
$ jar umf hello.jar META-INF/MANIFEST.MF
java.io.IOException: invalid header field
at java.util.jar.Attributes.read(Attributes.java:354)
at java.util.jar.Manifest.read(Manifest.java:161)
at java.util.jar.Manifest.<init>(Manifest.java:56)
at sun.tools.jar.Main.update(Main.java:487)
at sun.tools.jar.Main.run(Main.java:168)
at sun.tools.jar.Main.main(Main.java:904)
Anyone point me to a good manifest ref?
Thanks Neil
[ September 13, 2002: Message edited by: Neil Laurance ]
Neil Laurance
Ranch Hand

Joined: Jul 18, 2002
Posts: 183
I sussed it. Eventually
djoejoe
Greenhorn

Joined: Sep 13, 2002
Posts: 1
Ok this is just some of the basics lets say you have a .class called helloworld and you are useing the jdk
to put that class into a jar you would do something like this at the commandline
jar cf aname.jar helloworld.class
this would that class, note this class has the main()mothod in it.
now let make that jar runnable and change the mainifest file
We mak a txt file called mf.txt and we put this in there
Manifest-Version: 1.0
Main-Class: myjar
Name :myjar
and save it now at the commandline we
do this
jar umf mf.txt aname.jar
and this should change the mainfest file that was made by default for you and it should make your jar double clickable for windows

ps I hope this helps
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
djoejoe,
Welcome to JavaRanch!
We ain't got many rules 'round these parts, but we do got one. Please change your display name to comply with The JavaRanch Naming Policy.
Thanks Pardner! Hope to see you 'round the Ranch!


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
So, what does I sussed it. mean?
Joe Joe
Greenhorn

Joined: Sep 13, 2002
Posts: 5
I made a bobo
Where you see this
Manifest-Version: 1.0
Main-Class: myjar
Name :myjar
where you see myjar it should be helloworld cause that would be your main class that has the main() method
anyways see you around partner
Neil Laurance
Ranch Hand

Joined: Jul 18, 2002
Posts: 183
Originally posted by Dirk Schreckmann:
So, what does I sussed it. mean?

Its English slang for: I figured it out. I played around with the order of the arguments to the jar command, and got it to work
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Updating a JAR manifest