Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: Could not find or load main class - Java cygwin

Using cygwin on windows 7.

To compile all my files I do:

javac -cp ./antlr-3.2.jar *.java

which works fine. Then I try

java -cp .:./antlr-3.2.jar Interpreter

where interpreter is a .java file that I know is in the current directory. I thought adding . to the classpath would fix my problem but I am still getting

Error: Could not find or load main class Interpreter
like image 384
bender Avatar asked Apr 22 '13 06:04

bender


People also ask

What is error could not find or load main class?

When you get the message "Could not find or load main class ...", that means that the first step has failed. The java command was not able to find the class. And indeed, the "..." in the message will be the fully qualified class name that java is looking for.

Could not find or load main class when running a jar?

When the JVM is unable to locate the main class, it's often because it's looking for the corresponding . class files in the wrong classpath. Of course, the way to rectify this problem is to manually specify the classpath by either using packages or specifying the classpath.


1 Answers

Even though you are running under cygwin, the java.exe is still a windows program.

It needs ; as class path delimiter. Try ,

java -cp ".;./antlr-3.2.jar" Interpreter

or

java -cp .\;./antlr-3.2.jar Interpreter

You need to escape or quote the classpath correctly so that it is not interpreted by shell.

like image 75
Jayan Avatar answered Oct 25 '22 00:10

Jayan