Thursday 25 June 2020

Can't execute jar- file: “no main manifest attribute”

https://stackoverflow.com/questions/9689793/cant-execute-jar-file-no-main-manifest-attribute


That is because Java cannot find the Main attribute in the MANIFEST.MF file. The Main attribute is necessary to tell java which class it should use as the application's entry point. Inside the jar file, the MANIFEST.MF file is located in META-INF folder. Wondering how you could look at what's inside a jar file? Open the jar file with WinRAR.
The main attribute inside the MANIFEST.MF looks like this:
Main-Class: <packagename>.<classname>
You get this "no main manifest attribute" error when this line is missing from the MANIFEST.MF file.
It's really a huge mess to specify this attribute inside the MANIFEST.MF file.
Update: I just found a really neat way to specify the Application's entry point in eclipse. When you say Export,
Select Jar and next 

[ give it a name in the next window ] and next

and next again

and you'll see " Select the class of the application entry point".

Just pick a class and Eclipse will automatically build a cool MANIFEST.MF for you.
enter image description here

No comments:

Post a Comment