buildantantlrantlr3build.xml

Is it possible to use multiple Java versions within same build.xml - ANT build. - ANTLR3.3


I am working on a legacy project which needs to be upgraded to use Java8. During the upgrade we are facing issues with ANTL3.3 as it not compatible with Java8.

Now because of certain dependencies we cannot upgrade ANTLR version and ANTLR is used to generate Java files from Grammar(.g) files.

Now, in the ANT - build.xml. I want to divide it in 2 parts.

  1. In which ANTLR target is run wherein the Grammar files being converted to Java files using. During this part I want to use Java1.7.

    ANTLR - Garmmar ===Java1.7===> output generated Java files

  2. Once Java files generated with 1.7 it should be compiled with existing Java files using Java8 and then final package should be prepared.

    Generated Java files + existing java source code ===Java8===> Compile classes


Solution

  • Presumable you use the java Ant task to generate lexer- and parser classes from your .g grammar file, then you could use the jvm attribute to point to your 1.7 Java binary:

    <java
        jvm="/path/to/java-1.7/bin/java" 
        classname="org.antlr.Tool" 
        fork="true"
        failonerror="true"
        maxmemory="1024m">
      
      <arg value="T.g" />
      <classpath refid="classpath" />
    </java>
    

    where <classpath ... points to your ANTLR 3.3 JAR (and other classes you need might need in the classpath):

    <?xml version="1.0" encoding="UTF-8"?>
    <project>
        <path id="classpath">
            ...
            <fileset dir="lib">
                <include name="*.jar" />
            </fileset>
        </path>
        ...
    </project>