This discussion is archived
3 Replies Latest reply: Apr 6, 2013 11:01 PM by Ayham RSS

Could not find the main class

Ayham Newbie
Currently Being Moderated
Hello All,
I face problem when i try to create JAR File.
After Creation of Jar file i tried to run it but error message
Could not find main class.

i follw this steps
1) my WordNetOK.java
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
import edu.smu.tspell.wordnet.*;


public class WordNetOK{

    public static void main(String args[]) throws FileNotFoundException {

System.setProperty("wordnet.database.dir", "C:\\Program Files (x86)\\WordNet\\2.1\\dict\\");
WordNetDatabase database = WordNetDatabase.getFileInstance();
      String result = "";
        NounSynset nounSynset;
        NounSynset[] hyponyms;
   
        //creating File instance to reference text file in Java
        File text = new File("C:/javacode/WordNetin.txt");
      
        //Creating Scanner instnace to read File in Java
        Scanner scnr = new Scanner(text);
      
        //Reading each line of file using Scanner class
        int lineNumber = 1;
        while(scnr.hasNextLine()){
            String line = scnr.nextLine();
      Synset[] synsets = database.getSynsets(line);
      for (int i = 0; i < synsets.length; i++) { 
      String[] wordForms = synsets.getWordForms();
     for (int j = 0; j < wordForms.length; j++) {
System.out.println(wordForms[j]);
     }
          }

//System.out.println("line " + lineNumber + " :" + line);

lineNumber++;
}

}

}
2) Javac WordNetOK.java

it create a class file

3) i create Manifeast.txt 
Main-Class:WordNetOK
4) i run this
C:\Javacode>jar cvfm WordNetOK.jar Manifest.txt WordNetOK.class
added manifest
adding: WordNetOK.class(in = 743) (out= 435)(deflated 41%)
5) i tried to execute it as * java -jar WordNetOK.jar *

But error appear could not find main class
C:\Javacode>java -jar WordNetOK.jar
Exception in thread "main" java.lang.NoClassDefFoundError: WordNetOK
Caused by: java.lang.ClassNotFoundException: WordNetOK
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class: WordNetOK . Program will exit.

C:\Javacode>
Note : i execute the classpath at beginning
set PATH=C:\Program Files\Java\jdk1.6.0_32\bin;
set CLASSPATH=C:\Program Files\Java\jdk1.6.0_32\bin;\javacode;
Edited by: Ayham on Apr 6, 2013 7:39 AM

Edited by: Ayham on Apr 6, 2013 7:41 AM

Edited by: Ayham on Apr 6, 2013 7:45 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points