Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help with this jar file

 
ben riches
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Billybob Marshall
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try
jar cwfm apple.jar mainclass -c:\j21work\I\
 
Lalit K Kumar
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic