Java – error: unable to find or load the main class test
•
Java
I'm currently teaching myself ANTLR. When I finished the book "the defined ANTLR reference", I encountered a problem I'm doing the first example, creating a syntax file, getting my lexer and parser java files, and creating the following Java programs to test it:
import org.antlr.runtime.*; public class Test { public static void main(String[] args) throws Exception { ANTLRInputStream input = new ANTLRInputStream(system.in); TLexer lexer = new TLexer(input); CommonTokenStream tokens = new CommonTokenStream(lexer); TParser parser = new TParser(tokens); parser.r(); } }
Then I use the command line to compile which works normally, and then I try to run the Java class, which fails. The whole command line is as follows:
C:\Users\Dan\workspace\Test\src>dir Volume in drive C is Acer Volume Serial Number is ECB2-5E39 Directory of C:\Users\Dan\workspace\Test\src 17/09/2012 18:15 <DIR> . 17/09/2012 18:15 <DIR> .. 17/09/2012 18:32 723 Test.class 16/09/2012 20:51 353 Test.java 17/09/2012 18:32 3,641 TLexer.class 15/09/2012 21:35 7,625 TLexer.java 17/09/2012 18:32 2,425 TParser.class 15/09/2012 21:35 2,115 TParser.java 6 File(s) 16,882 bytes 2 Dir(s) 235,276,161,024 bytes free C:\Users\Dan\workspace\Test\src>javac -cp C:\antlr-3.4.jar TLexer.java TParser.j ava Test.java C:\Users\Dan\workspace\Test\src>java -cp C:\antlr-3.4.jar Test Error: Could not find or load main class Test C:\Users\Dan\workspace\Test\src>
I've seen a lot of solutions, and none seems to suit me The following are good:
>JDK and JRE are completely up to date > path set
Solution
Add current location to classpath:
java -cp C:\antlr-3.4.jar;. Test
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码