I create jar file with command.
$jar -cvf A.jar A.class
I tried executing
$java -jar A.jar
I am getting below error.(Before adding “Main-class : A” to manifest.mf)
Failed to load Main-Class manifest attribute from A.jar
contents of MANIFEST.MF
Manifest-Version: 1.0
Created-By: 1.6.0_18 (Sun Microsystems Inc.)
Main-Class: A
Now i am getting
Exception in thread "main" java.lang.NoSuchMethodError: main
Usually you don’t need to specify an Manifest file when you create a jar, but as you want to start your jar by launching
java -jaryou must specify your own manifest which details where is the class containing themain()method.In order to do this you have to create a file containing this line :
(I suppose A is your class containing your main method, if it isn’t the case specify the FQN of your desired class)
and create your jar with the following command :
For example :
After your edit :
You must have a
main()method in yourAclass you want to launch. Check the link below.Resources :