jar cvef Main.jar Main *
added manifest
adding: DrawPane.class(in = 344) (out= 257)(deflated 25%)
adding: DrawPane.java(in = 306) (out= 175)(deflated 42%)
adding: main(in = 9038) (out= 8275)(deflated 8%)
adding: Main.class(in = 868) (out= 544)(deflated 37%)
adding: Main.java(in = 507) (out= 260)(deflated 48%)
adding: Manifest.txt(in = 18) (out= 18)(deflated 0%)
adding: src/(in = 0) (out= 0)(stored 0%)
adding: src/icon.png(in = 1163) (out= 1168)(deflated 0%)
adding: src/Thumbs.db(in = 3584) (out= 1038)(deflated 71%)
jar file created, then:
java -jar Main.jar
I get an error:
no main manifest attribute, in Main.jar
what I'am doing wrong?
You might get this error when the Main-Class entry is missing in MANIFEST. MF file. You can put the maven-jar-plugin plugin in pom. xml to fix it.
For a JAR file to run, the JAR itself must contain at least one class that has a runnable main method. Furthermore, the class with the main method must be listed as the main-class in the JAR's manifest file. If not, the class must be explicitly stated on the command line when the JAR is run.
As per this tutorial your manifest file should have relative path META-INF/MANIFEST.MF
. It doesn't look like you added your own manifest there. The jar
command adds a default manifest, that's why it says 'manifest added'.
EDIT: As per the next page in the tutorial, the basic syntax to add content to the manifest file is the following:
jar cfm jar-file manifest-addition input-file(s)
I recommend to read the first few section of the tutorial and I'm sure you'll get the result you want!
make sure to write 1 space after ":" and new line after class name and save it that way. jar tool syntax:
jar -cvmf manifest.txt appname.jar ClassName.class
after running tool , run jar file with
java -jar appname.jar
Content of manifest.txt file
Main-Class:(1space)ClassName(press enter for new line)
Hope it 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