Software Setup

Most in-class exercises require you to have an environment with Git, JDK 8+, and Apache Ant installed and configured. Git and the JDK usually come with installers, but the Ant installation may be tricky, especially if you are not familiar with the PATH environment variable.

Ant Installation, Simplified

The official installation documentation of Ant asks you to do additional steps that are not required to make the ant command work. In most cases, neither ANT_HOME nor JAVA_HOME is necessary. Ant is still very likely to work even without these two environment variables set. Thus, you may ignore them unless a problem emerges.

Here is a minimal set of steps required to get Ant running:

  1. Download a Zip file or a tarball from Ant website, and extract it to somewhere on your disk, preferably an accessible location. Ant version 1.9.x or above should work.

  2. In the extracted folder (e.g., apache-ant-1.10.9 if you downloaded v1.10.9), there is a bin directory in which you can find some ant executables for different shells. Copy the absolute path to this bin directory.

  3. Add the path you just copied to the PATH environment variable’s value.

  4. Open a new terminal.

The ant command should be working now. You can try and run commands like ant compile and ant clean in the basic-stats project.

What Is PATH? Why Do I Need to Set It?

PATH tells your system where it is supposed to find the executable for every command you issue.

When you install a program, its executable is placed under some path in the file system. Let’s say you are installing Git, whose main executable’s file name is simply git. On Linux, it will typically be installed to /usr/bin/git; on Windows, it will be copied to C:\Program Files\Git\bin\git.exe by default. After the Git installation, you can invoke Git with command /usr/bin/git on Linux or C:\Program Files\Git\bin\git.exe on Windows. However, it takes too much time to type such a long command, let alone to remember it.

If you have used Git in CLI before, you must have noticed that if you would ever need to run Git, you would just type git instead of the full path to the Git executable. This is way more convenient, and you probably have been taking it for granted. In fact, it’s not; you can leave out the full path only if the path is included in the PATH variable.

/usr/bin is typically included in PATH on Linux by default, and most Linux software packages install their executables to /usr/bin as a standard, so that’s why you don’t need to worry about PATH configuration on Linux if all packages you install adhere to this standard. On Windows, however, things are a little bit more complicated, because Windows does not have a de facto standard with respect to where software packages’ executables should be stored.

Let’s take Python 3.9 as an example. On Linux, the typical installation destination of its main executable is /usr/bin/python, still under /usr/bin; on Windows, it is C:\Program Files\Python39\python.exe, which is not in the same directory as Git executable. Therefore, installation of development tools on Windows typically requires you to add the installation path to PATH as an extra step.

A lot of development tools on Windows offer an installer that typically updates PATH automatically for you. That’s why you didn’t have the hassle of dealing with PATH when you set up Git and JDK, because they are usually shipped as installers. Unfortunately, this is not the case for Ant. The official Ant distribution only provides you Zips and tarballs, not installers. You can extract the files to a folder in your file system, and the ant executable resides in the bin subfolder in it. However, at this point your system still doesn’t know there’s an ant command in that subfolder, so if you run ant, your system complains that it cannot find that command.

Once you add the path to the folder containing the ant executable to your system’s PATH environment variable, it knows where to find it, so the ant command works.