aspose file tools*
The moose likes Beginning Java and the fly likes Help with this jar file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Help with this jar file" Watch "Help with this jar file" New topic
Author

Help with this jar file

ben riches
Ranch Hand

Joined: Nov 08, 2002
Posts: 126
Hello All,
I have this folder which holds my java class called apple, a text file called mainclass (which holds this: Main-Class: apple) and I have a jar file called apple aswell.
when I go to run the jar file to see the output I get this error:
C:\j21work\I>java -jar apple.jar
Failed to load Main-Class manifest attribute from
apple.jar
what have I done wrong here why can I not get any output?
Thanks
Ben
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
I am a newbie with creating jar files, but I suspect that you need to change the name of mainclass to manifest. I think there is also a way to specify the file to use as the manifest file, but I'm not exactly sure. Alternatively, you can specify a class name to run explicitly when you use the java command. In this case, you could use:
java -jar apple.jar Apple


Java API Documentation
The Java Tutorial
Billybob Marshall
Ranch Hand

Joined: Jan 27, 2004
Posts: 202
Originally posted by ben riches:
Hello All,
I have ... a text file called mainclass (which holds this: Main-Class: apple)...

Is that text file named "Manifest.mf" and is it in your jar's "meta-inf" folder?
ben riches
Ranch Hand

Joined: Nov 08, 2002
Posts: 126
Originally posted by Billybob Marshall:

Is that text file named "Manifest.mf" and is it in your jar's "meta-inf" folder?

the text file is named mainclass.txt, and where would my jar's meta-inf be?
Thanks
Ben
Jason Fox
Ranch Hand

Joined: Jan 22, 2004
Posts: 114
To add a Manifest file, simply use this syntax:
jar cvfm YourJar'sName.jar yourmanifesttextfile -C directorywithyourclassfiles/
if that works for you, use jar -tf YourJar'sName.jar to view the contents of the jar file
Jason
ben riches
Ranch Hand

Joined: Nov 08, 2002
Posts: 126
Originally posted by Jason Fox:
To add a Manifest file, simply use this syntax:
jar cvfm YourJar'sName.jar yourmanifesttextfile -C directorywithyourclassfiles/
if that works for you, use jar -tf YourJar'sName.jar to view the contents of the jar file
Jason


I done what you said and I keep getting this error:
c:\j21work\I>jar cwfm apple.jar mainclass -c:\j21work\I\apple.class
java.io.IOException: invalid header field

Thanks
Ben
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
Try
jar cwfm apple.jar mainclass -c:\j21work\I\
Lalit K Kumar
Ranch Hand

Joined: Jan 29, 2004
Posts: 32
hi,
Remember the extension of your manifest file must be .tmp and not .txt.
manifest.tmp must contain the following text:
Name: yourfilename.class
Java-Bean: True
now run the command
jar cfm yourfilename.jar manifest.tmp yourfilename.class
give the path of manifest file (instead of manifest.tmp) in case it is not in the same folder as your files are.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help with this jar file
 
Similar Threads
please clear me this...
help needed with creating jar file
Java installer file (.EXE)
how to specify a class file in jar
method in subclass not seeing method in abstract superclass