Hoa Vu
Hoa Vu

Reputation: 2933

JAVA could not find or load main class when I add external library

There are some encoding character in my code so I compile the code as follow:

javac -cp cayenne-2.0.4.jar Twokenize.java

It's ok. But when I run the program, it return an error:

java -cp cayenne-2.0.4.jar Twokenize test.txt

Here is an error:

Error: Could not find or load main class Twokenize

But when I just run:

java Twokenize test.txt

The program (main method) still runs smoothly util it meets the code that require external library. Please help me. Thank you very much.

Upvotes: 2

Views: 1410

Answers (1)

Jigar Joshi
Jigar Joshi

Reputation: 240948

when you use -cp it looses current directory from classpath so you need to specify explicitly

Use

java -cp .:cayenne-2.0.4.jar Twokenize test.txt

Upvotes: 6

Related Questions