JAR Problems: Failed to load Main-Class. HELP!!!
I have a manifest file called MyManifest.mf that has the following content (exactly the way it is between the double quotes).
"Manifest-Version: 1.0
Main-Class: BankSession.class"
Then I run the following command:
>jar cmf MyManifest.mf MyBank.jar *
Then I try to run my application with following command
>java -jar MyBank.jar
I get the following error:
Failed to load Main-Class manifest attribute from
MyBank.jar
PLEASE HELP!!!!
[512 byte] By [
jpanchal] at [2007-9-26 1:13:24]

I don't think you should have the .class extension just the full class name (including any pakage names).
I tried that but that didn't work. The class is not part of any package. It is just as it is with no package qualification.
Try adding a blank line at the end of the manifest file.
No, that didn't work. I got this error:j>ar cmf MyManifest.mf MyBank.jar *>java -jar MyBank.jar java.lang.NoClassDefFoundError: BankSession/classException in thread "main"
No, that didn't work. I got this error:>jar cmf MyManifest.mf MyBank.jar *>java -jar MyBank.jar java.lang.NoClassDefFoundError: BankSession/classException in thread "main"
You didn't try the first suggestion: remove the ".class" name from the name of the class. That is the name of the file the class is in, not the class itself!
Ok, I'll start all over again. Below is my manifest file called MyManifest.mf
"Manifest-Version: 1.0
Main-Class: BankSession"
I tried putting the new line after the BankSession word and I got this error trying to run the jar creation command.
"java.io.IOException: invalid manifest format
at java.util.jar.Manifest.read(Manifest.java:183)
at java.util.jar.Manifest.<init>(Manifest.java:59)
at sun.tools.jar.Main.run(Main.java:124)
at sun.tools.jar.Main.main(Main.java:778)
"
So I just got rid of the line after the BankSession word.
Then I run the following command:
>jar cmf MyManifest.mf MyBank.jar *
Then I try to run my application with following command
>java -jar MyBank.jar
I still get the following error:
Failed to load Main-Class manifest attribute from
MyBank.jar
No luck yet.
Hi....
Its strange to know that jar file is not working...
May be you are mising out something.. I am giving you the steps that would make the jar file..
1. Create the Manifest file with extension -.mf(.mf)
2. In the MyManifest file just type this
Main-Class: BlankSession
3. You can notice that after the BlankSession one blank line is entered ( just press Enter ) and then save the file.
4. Then run the command as follows
jar cmf MyManifest.mf MyBlank.jar *.*
5. java -jar MyBlank.jar
I hope this works out for you...
Deepak
It appears to me that you have a blank line between your Manifest-Versionand Main-ClassAfter removing it the jar file should workHope it helped :)
Ok, I tried that but now I get this error:"java.lang.NoClassDefFoundDrror: org/xml/sax/SAXException Exception in thread "main" "I don't understand that because I have jaxp.jar, crimson.jar, and xalan.jar my classpath. It would be great if someone could help.
This is how I do mine:
jar -cfm myJarName.jar myManifest allFilesToInclude.XXX
The manifest File needs to be plain text (extension does not matter) with the first line needs to have
Main-Class: myFilewithMain
notice no extension and the space between the : and the name.
first line:
Main-Class: BankSession
second line:
carriage return
if BankSession is inside a package
first line:
Main-Class: mypackage.BankSession
second line:
carriage return
jar cmf manifest.mf MyBank.jar *.class
When you have done unjar it jar xvf MyBank.jar
in an other directory and check that your class are there.
and look your manifext file.
if you are on windows and you have a jre installed double click in your jar file
jef06 at 2007-6-29 0:09:32 >
![top of Java-index,Archived Forums,Portability & Platform Independence [Archive]...](/library/images/10/top.gif)
> Ok, I tried that but now I get this error:
> "java.lang.NoClassDefFoundDrror:
> org/xml/sax/SAXException Exception in thread "main" "
>
> I don't understand that because I have jaxp.jar,
> crimson.jar, and xalan.jar my classpath. It would be
> great if someone could help.
If you are creating an executable jar, all the required classes must be present inside the jar. Executable jars simply wont take the classpath of the environment you are working. So try including all the required items inside the jar and try once more..
regards Stallon