I have installed an application, when I try to run it (it\'s an executable jar) nothing happens. When I run it from the commandline with:
java -jar \
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.
For me, none of the answers really helped - I had the manifest file in correct place, containing the Main-Class and everything. What tripped me over was this:
Warning: The text file from which you are creating the manifest must end with a new line or carriage return. The last line will not be parsed properly if it does not end with a new line or carriage return.
(source). Adding a newline at the end of the manifest fixed it.
You might not have created the jar file properly:
ex: missing option m in jar creation
The following works:
jar -cvfm MyJar.jar Manifest.txt *.class
You might have the same problem as I do. After creating your .jar file, write jar xf app.jar META-INF/MANIFEST.MF
. This will create a copy of the file to your current directory so you can read it. If it only says something like:
Manifest-Version: 1.0
Created-By: 1.8.0_51 (Oracle Corporation)
and does not contain the "Main-Class" declaration, then I think you found your problem.
I do not know how to solve it, though. I checked other people with same/similar problems on StackOverflow and couldn't find an answer. However with this information you can perhaps get some better help (given the fact that you have the same problem as I).
Edit: I had tried with a manifest-file but didn't get it to work, but my mistake was to only name one of the classes when creating the jar-file. I wrote *.class instead and it works now.
Although I don't know why there is a need to create a manifest-file. But I guess it's fine as long as it works.
For me this error occurred simply because I forgot tell Eclipse that I wanted a runnable jar file and not a simple library jar file. So when you create the jar file in Eclipse make sure that you click the right radio button
If the jar isn't following the rules, it's not an executable jar.