Could not find or load main class org.apache.tools.ant.launch.Launcher when running Ant builds in Bamboo

Platform Notice: Data Center Only - This article only applies to Atlassian products on the Data Center platform.

Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data-Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Except Fisheye and Crucible

Problem

The Ant executable works on the command line, when ant -f build.xml is run – however, running the same Ant build in Bamboo fails with either of the below errors:

1 2 3 Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/tools/ant/launch/Launcher Caused by: java.lang.ClassNotFoundException: org.apache.tools.ant.launch.Launcher ...
1 Error: Could not find or load main class org.apache.tools.ant.launch.Launcher

Cause

You have not specified your $ANT_HOME directory as the Ant capability path in Bamboo for the agent the build is executing on. The path to Ant in Bamboo likely points to a single Ant executable such as /usr/bin/ant which is only a symbolic link or wrapper script.

Solution

Locate your Ant installation directory ($ANT_HOME) and specify the path to your local Ant installation in Bamboo. Steps like these might be helpful to identify your Ant installation directory:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 localhost:~ root$ which ant /usr/bin/ant localhost:~ root$ ls -al /usr/bin/ant lrwxr-xr-x 1 root root 22 Nov 18 2011 /usr/bin/ant -> /usr/share/ant/bin/ant localhost:~ root$ ls -al /usr/share/ant/bin/ant -rwxr-xr-x 1 root root 9973 Nov 18 2011 /usr/share/ant/bin/ant localhost:~ root$ ls -al /usr/share/ant lrwxr-xr-x 1 root root 14 Nov 18 2011 /usr/share/ant -> java/ant-1.8.2 localhost:~ root$ ls -al /usr/share/java/ant-1.8.2/ total 16 drwxr-xr-x 7 root root 238 Jun 3 2011 . drwxr-xr-x 9 root root 306 Nov 18 2011 .. -rw-r--r-- 1 root root 15561 Nov 18 2011 LICENSE.txt -rw-r--r-- 1 root root 224 Nov 18 2011 NOTICE.txt drwxr-xr-x 8 root root 272 Jun 3 2011 bin drwxr-xr-x 15 root root 510 Jun 3 2011 etc drwxr-xr-x 35 root root 1190 Jun 3 2011 lib

In the above mentioned example the correct location for Ant should be /usr/share/java/ant-1.8.2/, or a path to a custom Ant installation directory.

Once identified, the Ant path can be defined at:

  • Local Agents: Bamboo Administration >> Server Capabilities >> Ant

  • Remote Agents: Bamboo Administration >> Agents >> (Select agent) >> Capabilities >> Ant

Bamboo will automatically append /bin/ant to the path defined in the Ant capability, so be sure to point it at the $ANT_HOME rather than directly at the binary.

Also, if the environment variable $ANT_HOME is defined and points to the Ant installation, Bamboo will add the Ant capability automatically on start-up.

Updated on April 16, 2025

Still need help?

The Atlassian Community is here for you.