Sunday, May 12, 2024
HomeJavaHow one can repair Didn't load Major-Class manifest attribute from jar in...

How one can repair Didn’t load Major-Class manifest attribute from jar in Java? Eclipse Netbeans Tutorial Instance


If in case you have tried creating JAR file and working Java program from command the road you could have encountered “Didn’t load Major-Class
manifest attribute from jar”
, This error which haunts many Java
programmer once they enter into command line enviornment and tries to create JAR file within the command line
or IDE like Netbeans and Eclipse
. The main downside with
“Failed
to load Major-Class manifest attribute from jar”
error is
that, it’s pointless creates panic which it does not deserve, perhaps as a result of the method entails of making and working JAR will not be that widespread like working Java
program utilizing the 
“java” command.


Anyway on this Java tutorial we are going to see Why  “Failed
to load Major-Class manifest attribute from the jar”
comes and
How one can repair  Didn’t load Major-Class manifest attribute from jar error.





Reason for Didn’t load Major-Class manifest attribute from the jar in Java

As I’ve mentioned beforehand, with a purpose to troubleshoot any error first look
on the error message, many instances it supplies necessary clue although I agree on some the time it additionally confuses or misleads primarily in case of these
NoClassDefFoundError and ClassNotFoundException


Right here the error message is related and clear “Didn’t load Major-Class
manifest attribute from the jar”
is saying that java command  did not load “Major-Class” attribute
from Manifest of JAR file, which you’re working, it means:

1) Both you haven’t offered “Major-Class” attribute
in Manifest file

2) You do not have a manifest file in your JAR

3) “Major-Class” attribute will not be spelled
appropriately

“Major-Class” attribute in MANIFEST.MF file
specifies this system entry level or identify of Major class, a category that incorporates the principal methodology in Java. The principle method is required to run Java program. 



In case your jar’s MANIFEST file
does not comprise
“Major-Class” than you may not run Java program using the command
“java -jar identify.jar” , it can end in “Failed
to load Major-Class manifest attribute from jar”



In subsequent
part we are going to see step-by-step examples of find out how to reproduce this error and
then find out how to repair Didn’t load Major-Class manifest attribute from the jar.



Instance
of “Didn’t load Major-Class manifest attribute from the jar”:

Failed to load Main-Class manifest attribute from jar - Eclipse Java Netbeans fixAs a way to create a JAR file from the command immediate, you want a MANIFEST.MF file which
should observe guidelines specified for manifest here http://docs.oracle.com/javase/tutorial/deployment/jar/appman.html
. One in every of t
he necessary guidelines is “Manifest file should finish with newline or
carriage return character”. Upon getting your manifest file prepared, you
are able to create the JAR file. 



On this instance, we are going to first create a JAR file whose
MANIFEST file does not comprise
Major-Class attribute
after which will see the way it runs.

right here is our MANIFEST.MF file:

consumer@Machine:~/java cat
MANIFEST.MF

Manifest-version: 1.0

There isn’t a Major-class attribute and right here is command to create JAR with
Manifest file:

consumer@Machine:~/java jar
-cvfm take a look at.jar MANIFEST.MF HelloWorld.class

-c for create

-v for verbose

-f for information

-m for manifest

Above command will create a JAR file named take a look at.jar with
MANIFEST file specified after
take a look at.jar and embody HelloWorld.class from identical
listing.

When you run this JAR utilizing java command
you
will get
Didn’t load Major-Class manifest attribute from
jar
as a result of our Manifest file does not comprise “Major-Class” entry:

consumer@Machine:~/java java -jar take a look at.jar

Didn’t load
Major-Class manifest attribute from take a look at.jar

Java will even throw Failed
to load Major-Class manifest attribute from take a look at.jar
 even you probably have Major-Class attribute
however not spelled appropriately so be careful for spelling mistake there.

How to fix Failed to load Main-Class manifest attribute from jar in Java? Netbeans Tutorial Example

How one can repair Didn’t load Major-Class manifest attribute from jar

Now we all know what’s inflicting this error, we will repair it by introducing
Major-Class” attribute in manifest file or correcting it in case
of any spelling mistake on “
Major-Class”. Additionally
keep in mind area between  attribute and its
worth after colon e.g.
“Major-Class:HelloWorld” won’t
work as a substitute it can throw
IOException while creating JAR file as shown
right here:

consumer@Machine:~/java cat MANIFEST.MF

Manifest-version:
1.0

Major-Class:HelloWorld

consumer@Machine:~/java jar -cvfm take a look at.jar MANIFEST.MF HelloWorld.class

java.io.IOException:
invalid header discipline

        at java.util.jar.Attributes.learn(Attributes.java:393)

        at
java.util.jar.Manifest.learn(Manifest.java:182)

        at java.util.jar.Manifest.<init>(Manifest.java:52)

        at
solar.instruments.jar.Major.run(Major.java:151)

        at
solar.instruments.jar.Major.principal(Major.java:1149)

Upon getting appropriate MANIFEST.MF simply
repeat the process of creating JAR and working it. This
time it shouldn’t throw any Error. Listed below are command examples of working Java
program from JAR file :

consumer@Machine:~/java cat
MANIFEST.MF

Manifest-version:
1.0

Major-Class:
HelloWorld

consumer@Machine:~/java jar -cvfm take a look at.jar MANIFEST.MF HelloWorld.class

added manifest

including:
HelloWorld.class(in = 450) (out= 311)(deflated 30%)

consumer@Machine:~/java java -jar take a look at.jar

Executing Java
Program from JAR file

This was the best way to repair Didn’t load Major-Class manifest
attribute from jar error,
when you find yourself making a JAR file from the command immediate
however if you’re creating JAR from Eclipse or Netbeans IDE, then you might want to
observe IDE particular steps. Fortunately each IDE asks you to decide on Major Class
whereas making a JAR.

That is all on How one can repair “Didn’t load Major-Class
manifest attribute from jar”
. We have now seen what could cause
“Didn’t load Major-Class manifest attribute from jar” error and the way
we will appropriate it. let me know you probably have seen this error resulting from every other
cause than incorrect “
Major-class” attribute
entry within the manifest file.

Different Java debugging tutorials from Javarevisited Weblog



RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments