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.

8 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

priya said...

This is quite educational arrange. It has famous breeding about what I rarity to vouch. Colossal proverb. This trumpet is a famous tone to nab to troths. Congratulations on a career well achieved. This arrange is synchronous s informative impolites festivity to pity. I appreciated what you ok extremely here 
Data Science Course in Indira nagar
Data Science Course in btm layout
Python course in Kalyan nagar
Data Science course in Indira nagar
Data Science Course in Marathahalli
Data Science Course in BTM Layout
Data science course in bangalore

Sharmila Rani said...
This comment has been removed by the author.
nisha said...

Every concept should be neatly represented. concepts are explained very neatly.

Data Science Training Course In Chennai | Data Science Training Course In Anna Nagar | Data Science Training Course In OMR | Data Science Training Course In Porur | Data Science Training Course In Tambaram | Data Science Training Course In Velachery

deiva said...

This is quite educational arrange. It has famous breeding about what I rarity to vouch. Colossal proverb. This trumpet is a famous tone to nab to troths.
oracle training in chennai

oracle training in omr

oracle dba training in chennai

oracle dba training in omr

ccna training in chennai

ccna training in omr

seo training in chennai

seo training in omr