title: ANTLR: code generation target requires ANTLR 4.7; it can't be loaded by the current ANTLR 1.0
body: <p>I have a problem with ANTLR4, (ANother Tool for Language Recognition) when trying to build a new target for PHP7.</p>
  
  <p>First I purged the installed ANTLR3 package with</p>
  
  <pre><code>apt-get remove --purge antlr antlr-doc libantlr3-runtime-java libantlr-java
  </code></pre>
  
  <p>from the Debian Linux box I am using.</p>
  
  <p>Then I forked and cloned the project ANTLR4 from github, programmed a new runtime PHP7, created a new class PHP7Target as a subclass of class Target and wrote a fitting PHP7.stg.</p>
  
  <p>Then I rebuilt ANTLR4 with</p>
  
  <pre><code>cd antlr4
  export MAVEN_OPTS=-Xmx1G
  mvn clean    
  mvn -DskipTests=true install
  </code></pre>
  
  <p>Using the grammar T.g4</p>
  
  <pre><code>grammar T;
  
  a
      : 'b'   #alt1
      | 'c'   #alt2
      ;
  
  b : 'x' | 'y' {} ;
  
  e : e '*' e
    | 'foo'
    ;
  </code></pre>
  
  <p>Trying to run ANTLR4 with</p>
  
  <pre><code>export CLASSPATH=~/.m2/repository/org/antlr/antlr4/4.7.1-SNAPSHOT/antlr4-4.7.1-SNAPSHOT-complete.jar:$CLASSPATH
  cd ~/.m2/repository/org/antlr/antlr4/4.7.1-SNAPSHOT
  java -jar ./antlr4-4.7.1-SNAPSHOT-complete.jar /tmp/T.g4 -Dlanguage=PHP7
  </code></pre>
  
  <p>I ran into the error</p>
  
  <pre><code>error(35):  PHP7 code generation target requires ANTLR 4.7; it can't be loaded by the current ANTLR 1.0
  </code></pre>
  
  <p>The error displays two times.</p>
  
  <p>Without the option -Dlanguage=PHP7 ANTLR will do its job and create the java-files for the grammar.</p>
  
  <p>Unfortunately I do not understand the error message. It seems, that an old ANTLR version is in use by the package and I do not know how to upgrade ANTLR to version 4 in this case. </p>
  
  <p>Can anybody help and tell me where my error is, please?</p>