User123
User123

Reputation: 57

error: could not load or find main class xyz

I have checked my java installations by compiling and running a HelloWorld program which works perfectly fine. The problem comes when I compile my program with certain jar files which are located in the same directory as my java file. This is what I've done.

javac -cp "A.jar:B.jar" MyProg.java

This generates the class file MyProg.class successfully. Next when I run the following command, it gives this error error: could not load or find main class MyProg The command is:

java -cp "A.jar:B.jar" MyProg

Next, I even tried next by moving the jars in a folder named lib and issued the following commands:

javac -cp "lib/*" MyProg.jar (works fine;generates a class file)
java -cp "lib/*" MyProg (issues the same error)

I am working on a linux machine. Can some one please resolve the error.

Upvotes: 0

Views: 158

Answers (1)

Reimeus
Reimeus

Reputation: 159854

Add the current path to the classpath

java -cp .:A.jar:B.jar MyProg

Upvotes: 2

Related Questions