[antlr-interest] Problem running book examples

John B. Brodie jbb at acm.org
Tue Jun 8 08:25:22 PDT 2010


Greetings!

On Tue, 2010-06-08 at 16:44 +0200, Andreas Kumlehn wrote:
> Hi all, 
> I want to develop a configuration file for some tool of mine and 
> therefore decided to dive into ANTLR. The definitive ANTLR reference 
> book arrived some days ago and I tried some of the examples from the book's website. 
> 
> To generate the lexer/parser and compiling the Java files the 
> following commands work without erros: 
> java -cp ./lib/antlr-3.1.3.jar:./lib/antlr-2.7.7.jar:./lib/ 
> stringtemplate-3.2.jar org.antlr.Tool Expr.g 
> javac -cp ./lib/antlr-3.1.3.jar:./lib/antlr-2.7.7.jar:./lib/ 
> stringtemplate-3.2.jar ExprLexer.java ExprParser.java Test.java 
> 
> When I try to run the provided testrig coded in Test.java with command 
> java -cp ./lib/antlr-3.1.3.jar:./lib/antlr-2.7.7.jar:./lib/ 
> stringtemplate-3.2.jar Test 
> results in the following error: 
> 
> Exception in thread "main" java.lang.NoClassDefFoundError: Test 
> Caused by: java.lang.ClassNotFoundException: Test 
>         at java.net.URLClassLoader$1.run(URLClassLoader.java:202) 
>         at java.security.AccessController.doPrivileged(Native Method) 
>         at java.net.URLClassLoader.findClass(URLClassLoader.java:190) 
>         at java.lang.ClassLoader.loadClass(ClassLoader.java:307) 
>         at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) 
>         at java.lang.ClassLoader.loadClass(ClassLoader.java:248) 
> 
> The commands above are from my Mac, but I tried this on a WinXP 
> machine, too (with adapted paths).
> 
> Current SDK is installed, everything else works fine. Any suggestions or hints?
> Thanks for helping! 

it appears that the current directory (e.g. ./) is not in the class path
when you try to execute the Test class

include ./ somewhere in your -cp stuff

or better yet add the ANTLR stuff to the $CLASSPATH environment
variable.

   -jbb




More information about the antlr-interest mailing list