I tried to create an executable jar using this command:
jar -cvfm h.jar Manifest.mf Whatever1.class Whatever2.class
The manifest contains this:
Main-Class: Whatever1
But if I try to run the jar, I get: Failed to load Main-Class manifest attribute from my.jar
. I extracted the jar, and I saw that the contents of it's manifest were this:
Manifest-Version: 1.0
Created-By: 1.6.0_18 (Sun Microsystems Inc.)
Why was my manifest ignored?
EDIT: I know that using the -e
flag I can specify an entry point, and jar will generate a correct manifest, but I'd like to know how to make this version work.
The manifest file is named MANIFEST. MF and is located under the META-INF directory in the JAR. It's simply a list of key and value pairs, called headers or attributes, grouped into sections.
Unable to execute jar- file: "no main manifest attribute." The above error message is thrown because of a missing entry of Main-Class in MANIFEST. MF file. You may encounter this problem in any configuration-based Java project.
What gives a JAR file this versatility? The answer is the JAR file's manifest. The manifest is a special file that can contain information about the files packaged in a JAR file. By tailoring this "meta" information that the manifest contains, you enable the JAR file to serve a variety of purposes.
Add a line break after the last line of Manifest.mf
I've noticed that not having a newline at the end of the manifest file causes this problem at times. See if adding a new line at the end of the manifest file helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With