How To Laid Upward Failed To Charge Main-Class Manifest Attribute From Jolt - Coffee Eclipse Netbeans Tutorial
If you lot receive got tried creating JAR file together with running Java programme shape ascendancy business you lot may receive got encountered "Failed to charge Main-Class manifest attribute from jar" , This error which haunts many Java programmer when they larn into into ascendancy business arena together with tries to create JAR file inwards ascendancy line or IDE similar Netbeans together with Eclipse. Major occupation amongst "Failed to charge Main-Class manifest attribute from jar" error is that, it’s unnecessary creates panic which it doesn't deserve, may hold upwards because procedure involves of creating together with running JAR is non that mutual similar running Java programme using "java" command. Anyway inwards this Java tutorial nosotros volition consider Why "Failed to charge Main-Class manifest attribute from jar" comes together with How to fix Failed to charge Main-Class manifest attribute from offend error.
Cause of Failed to charge Main-Class manifest attribute from offend inwards Java
As I receive got said previously, inwards social club to troubleshoot whatever error get-go await at the error message, many times it provides of import clue though I grip unopen to fourth dimension it also confuse or mislead mainly inwards instance of those NoClassDefFoundError together with ClassNotFoundException. Here error message is relevant together with clear "Failed to charge Main-Class manifest attribute from jar" is proverb that coffee command failed to charge "Main-Class" attribute from Manifest of JAR file, which you lot are running, it means:
1) Either you lot receive got non provided "Main-Class" attribute inwards Manifest file
2) You don't receive got a manifest file inwards your JAR
3) "Main-Class" attribute is non spelled correctly
"Main-Class" attribute inwards MANIFEST.MF file specify programme entry indicate or rear of Main class, a shape which contains main method inwards Java. Main method is required to run Java program. If your jar's MANIFEST file doesn't incorporate "Main-Class" than you lot tin not run Java program using ascendancy "java -jar name.jar" , it volition effect inwards "Failed to charge Main-Class manifest attribute from jar". In side past times side department nosotros volition consider measuring past times measuring illustration of how to reproduce this error together with than how to create Failed to charge Main-Class manifest attribute from jar.
Example of "Failed to charge Main-Class manifest attribute from jar":
In social club to create a JAR file from ascendancy prompt you lot ask a MANIFEST.MF file which must follow rules specified for manifest here http://docs.oracle.com/javase/tutorial/deployment/jar/appman.html . One of the of import dominion is "Manifest file must halt amongst novel business or railroad vehicle render character". Once you lot receive got your manifest file ready, you lot are ready to create JAR file. In this illustration nosotros volition get-go create a JAR file whose MANIFEST file doesn't incorporate Main-Class attribute together with therefore volition consider how it runs.
here is our MANIFEST.MF file:
user@Machine: /java cat MANIFEST.MF
Manifest-version: 1.0
There is no Main-class attribute together with hither is ascendancy to create JAR amongst Manifest file:
user@Machine: /java jar -cvfm test.jar MANIFEST.MF HelloWorld.class
-c for create
-v for verbose
-f for files
-m for manifest
Above ascendancy volition create a JAR file named test.jar amongst MANIFEST file specified later test.jar together with include HelloWorld.class from same directory.
When you run this JAR using coffee command you volition larn Failed to charge Main-Class manifest attribute from jar because our Manifest file doesn't incorporate "Main-Class" entry:
user@Machine: /java java -jar test.jar
Failed to charge Main-Class manifest attribute from test.jar
Java volition also throw Failed to charge Main-Class manifest attribute from test.jar even if you lot receive got Main-Class attribute but non spelled correctly therefore scout out for spelling fault there.
How to create Failed to charge Main-Class manifest attribute from jar
Now nosotros know what is causing this error, nosotros tin create it past times introducing "Main-Class" attribute inwards manifest file or correcting it inwards instance of whatever spelling fault on "Main-Class". Also cry back infinite between attribute together with its value later colon e.g. "Main-Class:HelloWorld" volition non function instead it volition throw IOException while creating JAR file equally shown here:
user@Machine: /java cat MANIFEST.MF
Manifest-version: 1.0
Main-Class:HelloWorld
user@Machine: /java jar -cvfm test.jar MANIFEST.MF HelloWorld.class
java.io.IOException: invalid header field
at java.util.jar.Attributes.read(Attributes.java:393)
at java.util.jar.Manifest.read(Manifest.java:182)
at java.util.jar.Manifest.<init>(Manifest.java:52)
at sun.tools.jar.Main.run(Main.java:151)
at sun.tools.jar.Main.main(Main.java:1149)
Once you lot receive got right MANIFEST.MF only repeat the process of creating JAR together with running it. This fourth dimension it should non throw whatever Error. Here is ascendancy examples of running Java programme from JAR file :
user@Machine: /java cat MANIFEST.MF
Manifest-version: 1.0
Main-Class: HelloWorld
user@Machine: /java jar -cvfm test.jar MANIFEST.MF HelloWorld.class
added manifest
adding: HelloWorld.class(in = 450) (out= 311)(deflated 30%)
user@Machine: /java java -jar test.jar
Executing Java Program from JAR file
This was the way to create Failed to charge Main-Class manifest attribute from offend error, when you lot are creating JAR file from ascendancy prompt but if you lot are creating JAR from Eclipse or Netbeans IDE, than you lot ask to follow IDE specific steps. Thankfully both IDE inquire you lot to select Main Class spell creating JAR.
That's all on How to create "Failed to charge Main-Class manifest attribute from jar". We receive got seen what tin crusade "Failed to charge Main-Class manifest attribute from jar" error together with how nosotros tin right it. allow me know if you lot receive got seen this error due to whatever other argue than wrong "Main-class" attribute entry inwards manifest file.
Further Learning
Beginners Eclipse Java IDE Training Course
Eclipse Debugging Techniques And Tricks
10 Java debugging Tips inwards Eclipse IDE
0 Response to "How To Laid Upward Failed To Charge Main-Class Manifest Attribute From Jolt - Coffee Eclipse Netbeans Tutorial"
Post a Comment