4

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

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?

Community
  • 1
  • 1
bernie2436
  • 22,841
  • 49
  • 151
  • 244
  • Rather than just "trying the advice", you should read and try to understand what the answers actually say. In particular, http://stackoverflow.com/a/18093929/139985 explains in great detail what the causes of this exception are. But you do need to read it ... AND the pages it links to ... because this is not a problem you can solve by "trying advice". You have to UNDERSTAND what you are doing. – Stephen C Jan 01 '15 at 01:27
  • @StephenC that's fair. But in this case, the issue was that the package had to be in a directory that mirrored the package declaration. Which was just something I did not know! (And just learned from SO...) – bernie2436 Jan 01 '15 at 17:27

2 Answers2

4

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.

jan.supol
  • 2,636
  • 1
  • 26
  • 31
1

Add the current directory to the runtime classpath

java -cp .:jar1:jar2 nlp.NER_Sample englishPCFG.ser.gz parser/data/testsent.txt
Reimeus
  • 158,255
  • 15
  • 216
  • 276