Could not find or load main class org.apache.tools.ant.launch.Launcher when running Ant builds in Bamboo
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:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/tools/ant/launch/Launcher
Caused by: java.lang.ClassNotFoundException: org.apache.tools.ant.launch.Launcher
...
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:
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.