1

I tried to compile my java file with an external jar in Ubuntu 14.04.

It works fine after I compile:

jeremy@Ubuntu:~/Desktop/project/src$ javac -classpath lib/jsch.jar MyFile.java

but I have the following error when I tried to run:

jeremy@Ubuntu:~/Desktop/project/src$ java -classpath lib/jsch.jar MyFile
Error: Could not find or load main class MyFile  
3

From the terminal run:

java -cp .:/path/to/jar/file MyFile  

where you replace /path/to/jar/file with the full path to your external .jar file which in your question is named jsch.jar and -cp is a shorter way of typing -classpath.

Explanation

. - current directory
: - separator character used to separate class paths
/path/to/jar/file - replace this with the full path to external .jar file

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.