11

I want to use Antlr to create parser and i followed instruction from

Here

after following all instruction while I am running following command antlr4 -visitor D:\T\arithmetic.g4 I am getting this error msg: Error: Could not find or load main class org.antlr.v4.Tool

using this jar file : C:\Program Files\Java\lib\antlr-4.6-complete.jar

yashpal
  • 326
  • 1
  • 3
  • 16

1 Answers1

12

Your CLASSPATH environment variable isn't set properly. One very good tutorial on setting up ANTLR4 is here. This includes instructions for Windows and Unix-based environments.

TomServo
  • 7,248
  • 5
  • 30
  • 47
  • I have also used the same link but still not working – yashpal Aug 08 '17 at 06:21
  • 1
    Thanks you were right it is due to CLASSPATH. but somehow I am not able to fix it so instead of setting it permanently I using the command prompt to set it for a specific session using the following command: SET CLASSPATH=.;D:\g4Files\antlr-4.7-complete.jar;%CLASSPATH% – yashpal Aug 10 '17 at 12:55
  • Thanks you were right it is due to CLASSPATH. but somehow I am not able to fix it so instead of setting it permanently I using the command prompt to set it for a specific session using the following command: SET CLASSPATH=.;D:\g4Files\antlr-4.7-complete.jar;%CLASSPATH% – yashpal Aug 10 '17 at 12:55
  • @yashpal There you go. That is the brute-force approach, but that works too. Well done! – TomServo Aug 10 '17 at 13:40
  • I have the same error and I had to solve with the brute-force way. Someone could install instructions from official guide https://github.com/antlr/antlr4/blob/master/doc/getting-started.md ? – Cesar Miguel Nov 27 '20 at 02:23
  • 2
    The tutorial has moved. It's now here : https://tomassetti.me/antlr-mega-tutorial/ My problem was different and really dumb. I had set CLASSPATH to the folder containing the jar file, not to jar file itself. – jeancallisti Aug 26 '21 at 07:32
  • @jeancallisti Thank you for the updated link! I've edited the answer to reflect the new location. – TomServo Aug 26 '21 at 16:33