Building OpenJDK

If you are looking for updated instructions on how to build the OpenJDK JDK Project, please see

The rest of this page describes how the compiler-grammar project was built in JDK 7.

Building the Project

The project is in a standard set of OpenJDK repositories. You can either clone the entire forest, and build a complete standalone version of OpenJDK containing the new compiler, or you can just clone and build the langtools to get a copy of javac.

In addition to all the normal dependencies for OpenJDK, to build the langtools repository, you need to download ANTLR 3.1.1 or later. There are two different bundles you can use.

For more details and other versions, see the ANTLR download page. Note that the version number is currently specified in the ANTLR jar file name, so if you use a newer version, you will have to update the langtools make/build.xml file accordingly.

When you build the langtools repository, you must set the variable antlr.home to a directory that contains lib/antlr-3.1.1.jar. If you download the full ANTLR source distribution, you can simply set antlr.home to the location where you unpack the bundle. If you just download the ANTLR 3.1.1 jar file, you must set up a directory to contain lib/antlr-3.1.1.jar and set antlr.home to point to that directory.


Assuming you have suitable copies of JDK and ANTLR 3.1.1 installed, the following commands will download and build the compiler-grammar/langtools repository.

  % cd work
  % hg clone
  % cd langtools
  % ant -f make/build.xml \ -Dantlr.home=/opt/antlr/3.1.1 build-javac

Once you have built javac in the langtools repository, the dist directory will contain a copy of the javac compiler in dist/lib/javac.jar. You can use this jar file in a number of ways.

Tool showing grammatical structure of Java code

Check out this simple tool for showing how a Java source file is parsed. ( Screenshot. )