How do I rebuild ANTLR v3?
Just run ant from the main directory where you see the build.xml file. Use the build target:
ant build
Or, for old people like Terence, you can do the following. Make sure the following two jars are in your CLASSPATH
antlr-3.0/lib/stringtemplate-3.0.jar
antlr-3.0/lib/antlr-2.7.7.jar
then jump into antlr-3.0/src directory and then type:
$ javac -d . org/antlr/Tool.java org/antlr/*/*.java org/antlr/*/*/*.java
Takes 9 seconds on my 1Ghz laptop or 4 seconds with jikes. Later I'll have a real build mechanism, though I must admit the one-liner appeals to me. I use Intellij so I never type anything actually to build.
Actually, this won't rebuild the grammars. If you touch the grammars, you need to convert all those Java:
cd antlr-3.0/src/org/antlr/tool
java antlr.Tool antlr.g
java antlr.Tool antlr.print.g
java antlr.Tool assign.types.g
java antlr.Tool define.g
java antlr.Tool buildnfa.g
cp ANTLRTokenTypes.txt ../codegen
pushd ../codegen; java antlr.Tool codegen.g; popd
That is for the v2-based grammars. There are actually two v3 grammars written in v3. Don't mess with them until I can rebuild all grammars in v3.
In my C#-ish environment, simply typing "ant build" does not work immediately. Rather, I have to do the following:
First, going to the root directory (where build.xml resides) and running ANT results in
C:\MyProjects\ANTLR3Explanations\antlr-2007-12-27.12>ant
Buildfile: build.xml
generator-prepare:
generator:
[antlr] java.lang.NoClassDefFoundError: antlr/Tool
[antlr] Exception in thread "main"
This can be corrected by setting the CLASSPATH explicitly (I assume here that you run ANT from the top-level untar directory):
set ANTLRLIB=.\lib
set CLASSPATH=%ANTLRLIB%\stringtemplate-3.1b1.jar;%ANTLRLIB%\antlr-2.7.7.jar;C:\eclipse\plugins\org.junit_3.8.1\junit.jar
where junit points to some arbitrary junit installation. Running ANT now will now produce a host of "duplicate class" errors:
[myjavac] C:\MyProjects\ANTLR3Explanations\antlr-2007-12-27.12\codegen\ANTLRLexer.java:61: duplicate class: org.antlr.tool.ANTLRLexer
[myjavac] public class ANTLRLexer extends antlr.CharScanner implements ANTLRTokenTypes, TokenStream
...etc. (13 such messages)
At this point, it is necessary to remove the "codegen.dir" from the sources to be compiled. This is done by removing (or commenting) the line
<pathelement location="${codegen.dir}" />
in the build.xml file (line 36 in the current build). Now, the compile will work (interestingly, after this, it is possible to re-insert the line; because of the lazy compile, everything will work fine from then on, it seems).