4

I am getting following error while executing compiled jar file. I have re installed my java but my problem is not solved yet.

Failed to load Main-class Manifest Attribute from
D:\Tools\Lodable_Creation\dist\Lodable_Creation.jar

Currently by MANIFEST.MF file looks like.

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.1
Created-By: 1.6.0-b105 (Sun Microsystems Inc.)
Main-Class: main
X-COMMENT: Main-Class will be added automatically by build

I am using Netbeans 6.9.1 IDE.

Code Hungry
  • 3,930
  • 22
  • 67
  • 95

3 Answers3

3

Use a package for your class. Make sure your class looks something like this (notice the package and the public class):

package com.foo;

public class Main {

    public static void main(String[] args) {
    }
}

After which you can specify Main-Class as so:

Main-Class: com.foo.Main
adarshr
  • 61,315
  • 23
  • 138
  • 167
2

As adarshr suggested, JVM is not able to find the class because it requires the fully-qualified name in the Main-Class attribute of Manifest file.

Actually, it is not really necessary to specify the main file. You can just give your JAR file as your classpath, and give the fully-qualified name of the class to run it using java.

Say your JAR is myJar.jar and the fully-qualified main file is com.user.Main. Then from the command line, go to the directory which has your JAR File and give :-

java -classpath myJar.jar com.user.Main

And this will run the Main class. You would also need to give the classes (or JARs) in the classpath which are used (imported) in your Main class.

See this link for the details.

whitehat
  • 2,381
  • 8
  • 34
  • 47
0

I have encountered this error when I have developed projects with a JDK(1.7 in my case) and the installed JRE was an older version(1.6). Try to update your JRE or change the JDK used, if possible, to match your JRE version.

Silviu Burcea
  • 5,103
  • 1
  • 29
  • 43