Search code examples
javalinuxcygwinclasspath

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

Solution

  • 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.