Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not find or load main class: what steps are next for debugging?

Tags:

java

I know there are many posts on this. I have tried the advice on those threads.

  • Could not find or load main class

  • What does "Could not find or load main class" mean?

I compile a class like this... (it creates a NER_Sample.class file)

javac -cp "jar1:jar2:nlp:" NER_Sample.java

Then I try to run it like this

java -cp "jar1:jar2:nlp:" NER_Sample englishPCFG.ser.gz parser/data/testsent.txt

I get Could not find or load main class NER_Sample

NER_Sample has the declaration package nlp;

But this gives the same error

java -cp "jar1:jar2:nlp:" nlp.NER_Sample englishPCFG.ser.gz parser/data/testsent.txt

What do I try next?

like image 839
bernie2436 Avatar asked Oct 15 '25 00:10

bernie2436


2 Answers

Use -Xdiag

It can happen the message Could not find or load main class NER_Sample really means the class is found but can not be loaded, since there are other referenced classes that are not found on classpath.

java -Xdiag will tell you more, such as what classes are missing next.

like image 142
jan.supol Avatar answered Oct 17 '25 14:10

jan.supol


Add the current directory to the runtime classpath

java -cp .:jar1:jar2 nlp.NER_Sample englishPCFG.ser.gz parser/data/testsent.txt
like image 40
Reimeus Avatar answered Oct 17 '25 14:10

Reimeus