Trouble with setting up ANTLR

5,591 views
Skip to first unread message

Dominick Marciano

unread,
Jan 27, 2014, 1:54:32 AM1/27/14
to antlr-di...@googlegroups.com
I recently downloaded the antlr-4.1-complete.jar files and I'm using the "The Definitive ANTLR4 Reference" book to learn it (as I have never used ANTLR before).  However I ran into an error message and I can't figure out how to fix it.  In section 1.2 "Executing ANTLR and Testing Recognizers" I was trying to use the runtime library called "TestRig" but when I tried to execute "java org.antlr.v4.runtime.misc.TestRig" at the command prompt I get the following error message "Error: Could not find or load main class org.antlr.v4.Tool"

The following are the directories that I'm using right now:

Java:           C:\Program Files (x86)\Java\jre7\bin
ANTLR Jar:  C:\Users\Dominick\Desktop\Programming\ANTLR\Binaries
Hello.g4:      C:\Users\Dominick\Desktop\Programming\Grammars\Hello

I've tried executing the command while the current directory was the "Binaries" and "Hello" directories but I get the same error message.  I also set up a shortcut to the command prompt to run a script when it starts to set up some aliases, specifically:

DOSKEY grammars=cd C:\Users\Dominick\Desktop\Programming\ANTLR\Grammars\$1
DOSKEY antlr=java -jar C:\Users\Dominick\Desktop\Programming\ANTLR\Binaries\antlr-4.1-complete.jar $1

I suspect the problem is related to the CLASSPATH and/or PATH variables, but I'm not complete sure how to set these up.  Under Environment Variables, the following are present:

User Variables
CLASSPATH
C:\Program Files (x86)\Java\jre7\bin\ (I manually added this)

PATH:            
C:\Program Files (x86)\Microsoft Visual Studio 2008 SDK\VisualStudioIntegration\Tools\Sandcastle\ProductionTools\
C:\Program Files (x86)\Java\jre7\bin\ (I manually added this)

System Variables
CLASSPATH
C:\Program Files (x86)\Java\jre7\bin\ (I manually added this)

Path:
C:\Program Files (x86)\Intel\iCLS Client\;
C:\Program Files\Intel\iCLS Client\;
%SystemRoot%\system32;
%SystemRoot%;
%SystemRoot%\System32\Wbem;
%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;
C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;
C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;
C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;
C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT
;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x86;
C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x64;
C:\Program Files\Microsoft\Web Platform Installer\;
C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\;
C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;
C:\Program Files (x86)\Microsoft SDKs\TypeScript\;
C:\PROGRA~1\CONDUS~1\DISKEE~1\;
C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\
C:\Program Files (x86)\Java\jre7\bin\ (I manually added this)

Everything else seems to working so far.  For example, if I type the following two commands:

grammars Hello
antlr Hello.g4

The current directory will change to C:\Users\Dominick\Desktop\Programming\ANTLR\Grammars\Hello (where I have my Hello test grammar) and all the files it's suppose to create are created (e.g. Hello.tokens, HelloLexer.java, HelloListener.java, etc.).  I just can't get the "TestRig" tool to run.  

Thanks in advanced for any help with this.  I really don't want to continue with the book until I can get this working since I assume I'm going to need to use this later on.

~Dominick

Mike (IMAP)

unread,
Jan 27, 2014, 5:10:55 AM1/27/14
to antlr-di...@googlegroups.com, Mike Cargal
To execute TestRig, you’re going to need to have the ANTLR jar file in your classpath.  You only have Java itself in your classpath.

--
You received this message because you are subscribed to the Google Groups "antlr-discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to antlr-discussi...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Mahesh S Patil

unread,
Jan 20, 2017, 1:01:57 PM1/20/17
to antlr-discussion, mi...@cargal.net
I m facing problem while running following command
$ antlr4 Hello.g4
on windows. I have followed all the steps given in 

But when i run the command  antlr4 Hello.g4 i get a error

D:\antlr>antlr4 Hello.g4

D:\antlr>java org.antlr.v4.Tool Hello.g4
Error: Could not find or load main class org.antlr.v4.Tool

Following are my ClASSPATH
.;C:\Program Files\Java\jdk1.8.0_102\lib; D:\antlr\antlr-4.6-complete.jar

and system PATH
D:\antlr\bin
Reply all
Reply to author
Forward
0 new messages