-2

I wrote a simple java program that will require external jar file to compile and run. I've successfully compiled the .java file but i keep getting "Error: could not find or load main class 'Simple' " whenever i try to run the .class file using java command

Ismail
  • 445
  • 1
  • 5
  • 20

3 Answers3

1

You are missing your class itself in classpath, use . while running your code

On windows:

java -classpath external.jar;. MyClass

On linux:

java -classpath external.jar:. MyClass
0

You can use the -classpath argument of javac.

javac -classpath path/to/library1.jar MyClass.java

screab
  • 169
  • 3
  • 14
  • Yeah, I've compiled it with such command but here is the command i used to run it "java -classpath external.jar MyClass" – Ismail Dec 22 '16 at 11:10
  • You need to compile with javac, not with java – screab Dec 22 '16 at 11:11
  • Also, I think you need to put .java after MyClass. Try "javac -classpath external.jar MyClass.java" – screab Dec 22 '16 at 11:13
  • I did it and it compiles successfully using the command you provided. It generated a .class file as expected – Ismail Dec 22 '16 at 11:14
0

You need to set your CLASSPATH environment variable. refer this link for more information on CLASSPATH variable.

Harry
  • 75
  • 2
  • 10