title: Running ANTLR grun (TestRig) on grammar in a package.
body: <p>I have all the generated java files in a single directory after ANTLR execution, so I used some options to generate a separate directory and namespace to be stored and compiled to store all the generated files. </p>
  
  <p>This is the grammar file:</p>
  
  <p>grammar Expr;</p>
  
  <pre><code>prog: (expr NEWLINE)* ;
  expr: expr ('*'|'/') expr
      | expr ('+'|'-') expr
      | INT
      | '(' expr ')'
      ;
  NEWLINE : [\r\n]+ ;
  INT     : [0-9]+ ;
  </code></pre>
  
  <p>I could get the generated files in a different directory with <code>o</code>, and add package information with <code>package</code> option. </p>
  
  <pre><code>java -jar /usr/local/lib/antlr-4.5.3-complete.jar -listener -visitor -package expr -lib . -o gen/expr Expr.g4
  </code></pre>
  
  <p>Compiling the code requires <code>d</code> and <code>sourcepath</code> option in <code>javac</code>. </p>
  
  <pre><code>javac -cp .:/usr/local/lib/antlr-4.5.3-complete.jar -d out -sourcepath gen gen/expr/Expr*.java
  </code></pre>
  
  <p>I could check the code works from making the executable. </p>
  
  <pre><code>import expr.*;
  import org.antlr.v4.runtime.ANTLRInputStream;
  import org.antlr.v4.runtime.CommonTokenStream;
  import org.antlr.v4.runtime.tree.ParseTree;
  
  import java.io.File;
  import java.io.FileInputStream;
  import java.io.IOException;
  
  class ExprRunner {
      public static void main(String[] args) throws Exception {
          // create a CharStream that reads from standard input
  
          String filePath = "input.txt";
          File fileInput = new File(filePath);
          FileInputStream fileInputStream = new FileInputStream(fileInput);
  
  
          ANTLRInputStream input = new ANTLRInputStream(fileInputStream); 
          ExprLexer lexer = new ExprLexer(input); 
          CommonTokenStream tokens = new CommonTokenStream(lexer); 
          ExprParser parser = new ExprParser(tokens);
          ParseTree tree = parser.prog(); // begin parsing at init rule
          System.out.println(tree.toStringTree(parser)); // print LISP-style tree        
      }
  }
  </code></pre>
  
  <p>I could build and run it.</p>
  
  <pre><code>javac -cp .:/usr/local/lib/antlr-4.5.3-complete.jar:out -d out -sourcepath . ExprRunner.java
  java -cp .:/usr/local/lib/antlr-4.5.3-complete.jar:out ExprRunner
  </code></pre>
  
  <p>This is the directory structure. </p>
  
  <p><a href="https://i.stack.imgur.com/5uVaZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5uVaZ.png" alt="enter image description here"></a>
  After checking everything works fine, I tried to use grun (TestRig). I tried <code>grun Expr prog -tree</code> and <code>grun out/expr/Expr prog -tree</code>, but they did not work. </p>
  
  <p>How to run <code>grun</code> on the ANTLR files located in other directories?</p>