1

I am trying to setup ANTLR4 and I am having issues setting the classpath. I followed the instructions in the book "The Definitive ANTLR 4 Reference 2nd Edition", in section "Installing ANTLR", also I followed the instructions here and I have not got any results running in command line antlr4 or grun (the alias created).

I am running on a MacbookPro M1, Monterrey. I tried this with java 11 and 8 and the results were the same. I use sdkman to handle multiple java versions. Also my default terminal is oh-my-zsh.

In my bash_profile I added ANTLR configurations like this: enter image description here

and in file zshrc I am loading configuration from bash_profile.

This is the output from my terminal.

Output in terminal

darielrll
  • 71
  • 1
  • 5
  • 1
    Why not try the "new way": `pip install antlr4-tools`? antlr.org was just updated. – kaby76 Oct 05 '22 at 16:28
  • 1
    Thanks for your answer @kaby76, you are right, it is working with your suggestion. But, I am still trying a way to use it without installing any other prerequisite like python + pip, if I do not find anything I will have to use the `pip` option. Thanks again for your answer. – darielrll Oct 05 '22 at 17:19

1 Answers1

2

Mac OS is gradually locking things down tighter and tighter on the system volume. While I think there's a good argument that /usr/local/ shouldn't be a part of that, it looks like it is.

Try placing your antler jar file some place within you home directory (perhaps changing all references to /usr/local to just be ~ (or maybe ~/local if you'd prefer to separate them out.)

I just downloaded the latest:

cd ~/lib
sudo curl -O https://www.antlr.org/download/antlr-4.11.1-complete.jar

changed by .zshrc to reference the new version:

export CLASSPATH=".:$HOME/lib/antlr-4.11.1-complete.jar:$CLASSPATH"
alias antlr4='java -jar $HOME/lib/antlr-4.11.1-complete.jar'
alias grun='java org.antlr.v4.gui.TestRig'

grun is running just fine

Mike Cargal
  • 6,610
  • 3
  • 21
  • 27
  • Thanks a lot for your answer @Mike Cargal, it makes sense, I tried your suggestion but the error is the same. I moved the file (antlr-4.11.1-complete.jar) into a folder in my local home directory and when I execute `java -jar antlr-4.11.1-complete.jar` the result is: `Error: Invalid or corrupt jarfile antlr-4.11.1-complete.jar`, it seems that the problem is with the jar library itself or with my java version or probably I am missing something. – darielrll Oct 07 '22 at 18:09
  • 1
    I've added a bit of detail to my answer, but it doesn't appear that the jar file is corrupt, since it's running here, and I downloaded it with curl. – Mike Cargal Oct 07 '22 at 21:26
  • I retried and it is working now creating a dedicated _lib_ folder inside my _$HOME_ path. Really thanks for your help. – darielrll Oct 11 '22 at 13:53