4
votes

I am trying to install Antlr 4.4 on Windows for the purpose of using pyfuzzy, a Python library for fuzzy logic that depends on Antlr's Python runtime to function. I've tried (naively) to get the Antlr runtimes for Python (2.7) without installing Antlr which of course was not successful.

So I've attempted to install Antlr following the instructions for Windows but I get the error any time I try to run it :

Error: Could not find or load main class org.antlr.v4.Tool

The antlr .jar file is in C:\JavaLib as are the two batch files (antlr4.bat, grun.bat) created verbatim from the installation instructions.

My CLASSPATH is (I did not have a CLASSPATH to begin with so I created one with my main Java directory and the path to the .jar file) :

C:\Program Files\Java\jdk1.7.0_21\lib;C:\Javalib\antlr4-complete.jar;

My PATH is (though I'm entirely sure if that's relevant) :

C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\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:\MinGW\bin;C:\QtSDK\mingw\bin; C:\Software\jflex-1.5.0\bin;C:\Program Files (x86)\Git\cmd;C:\Program Files (x86)\Git\bin;C:\Python27;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\DLR\Sumo\bin\;C:\JavaLib

EDIT : Have switched to Antlr v 3.5.2, have updated CLASSPATH accordingly, however I am still having the same problem. i.e. the command java org.antlr.Tool -3.5.2 leads to the same error.

Note : Have not udated the .bat files as the v3 installation instructions don't mention them.

2
Your question is fine, in the future avoid thanks and "this is my first time using the site" and use correct formatting for code blocks (4-space indentation works best, but you can use backticks for small blocks of inline code). Thanks. - user2629998

2 Answers

0
votes

What solved it for me was: move the antlr jar to a temp folder. ie c:\tmp then set the classpath = c:\tmp\antlr... For some reason no matter what I tried it would not work in any of the "Program" directories or children directories.

0
votes

I went against the official Antlr4 documentation mainly because I don't like additional environmental variables and path clutter and went for the Java JDK help by putting user libraries and archives into the subdirectory jre/lib/ext under the JDK root.

Example on my system is c:\Program Files\Java\jdk1.8.0_152\jre\lib\ext

Then created an antlr4.cmd file somewhere on my path:

@echo off
java org.antlr.v4.Tool %*

grun.cmd is very similar (also somewhere on my path):

@echo off
java org.antlr.v4.gui.TestRig %*

Usage is same as the official docs:

antlr4 Hello.g4
javac Hello*.java
grun Hello r -tree 

Then I started on a custom tool for VS2019...