Thursday, May 13, 2010

Failed to Load Main-Class Manifest Attribute......

A common problem encountered by almost every java beginners, including me myself, is having this error,

Failed to load Main-Class manifest attribute …”,

when they are trying to execute a compiled executable .jar file through command prompt.

Everything needed to run a jar file has been set, e.g. classpath, manifest file, etc. Yet after multiple checking and rechecking, you still unable to get the jar file run and, as a result, you get even more frustrated.

Take a look at the error message. What it says is that java.exe could not find the main class of our java application. The main class itself, as the entry point of a java application, is specified in file MANIFEST.MF.

So, you have to make sure that the main class is actually specified in the manifest file, i.e. the following line is available somewhere in your manifest file:

Main-Class: MyMainClass

If you doubt that, then open your .jar file through an archiver (WinZip, WinRar, etc), go to folder META-INF, double-click MANIFEST.MF and see if that line is already there, if not, then add the above line to the file and save it.

Oh… in case you don’t notice… MyMainClass is actually your main class name, so replace it with the full name of your main class (the name of the class along with its package, if any)

There is one more fact you need to know about manifest file. You need to put a line break after the last line of the file. Fail to do so, the last line of the file won’t be parsed properly. So, in accordance with that, don’t forget to insert a line break to the line where the main class is specified, otherwise the error message will still pop up.

4 comments:

Anonymous said...

Assalamualaikum..Hai Cut Bang, Trep that hana merumpok, Peu haba lawetnyo...
Ne halo keuno ilee, jeut tapegah haba : 0812 6999 175, Loen hana no. droen...

Saleum

M. Arif Syahrijal

Leena said...

Thank's for the very usefully information (intelligible to non-experts like me).

Anonymous said...

Thanks dude your easy solution to the problem with manifest file just saved my life! May God Bless U!

Java pro said...

Here is another way to fix failed to main class manifest attribute from JAR in Eclipse