3

I am trying to get apache ant 1.8 to work under CentOS. First, I had this error.

Error: Could not find or load main class org.apache.tools.ant.launch.Launcher

Then I set the following variables according to this link:

Ant: Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/tools/ant/launch/Launcher

It's not CentOS, but I did verify the paths exist except JAVA_HOME, so I set it according to this site:

https://serverfault.com/questions/50883/what-is-the-value-of-java-home-for-centos

Now I am getting the same error I did the first time. It does not matter which ant rule I use, I still get the same error.

[alpha:~]
[bullshark]% export JAVA_HOME=/usr/lib/jvm/jre-1.7.0-openjdk.x86_64/
[alpha:~]
[bullshark]% export ANT_HOME=/usr/share/ant/
[alpha:~]
[bullshark]% export PATH=$PATH:$ANT_HOME/bin
[alpha:~]
[bullshark]% cd JRobo 
[alpha:JRobo] on master
[bullshark]% ant clean-and-fat-jar 
Picked up _JAVA_OPTIONS: -Xmx64m
Error: Could not find or load main class org.apache.tools.ant.launch.Launcher
[alpha:JRobo] on master
[bullshark]% cat /etc/redhat-release 
CentOS release 6.3 (Final)
[alpha:JRobo] on master
[bullshark]% 

You can clone him on CentOS if you want to try:

https://github.com/BullShark/JRobo

For Apache Ant 1.8 on CentOS:

http://www.jpackage.org/browser/rpm.php?jppversion=6.0&id=11867

For a package or manually:

https://ant.apache.org/bindownload.cgi?Preferred=ftp://apache.mirrors.pair.com/

Community
  • 1
  • 1
BullShark
  • 85
  • 2
  • 4
  • 12
  • what does "which ant" return? – asgs Mar 29 '13 at 07:18
  • I had problems getting ANT to work properly using the package manager. Different jars have been split out into different RPM packages... I found it a lot simpler to just download the ANT binary release and install it under the "/opt" directory. – Mark O'Connor Mar 29 '13 at 12:13
  • % which ant /usr/bin/ant – BullShark Mar 29 '13 at 19:02
  • I switched from CentOS 6.3 to Fedora 17, and now I have all the latest java packages. I'm running apache tomcat 1.7 and ant 1.8 from rpm packages without problems now. – BullShark Apr 23 '13 at 22:43

1 Answers1

16

Here are the steps required to get ant 1.8 installed on CentOS:

  1. Download http://archive.apache.org/dist/ant/binaries/apache-ant-1.8.4-bin.tar.gz
  2. Copy the tarball to your CentOS home folder (if it's not already there)
  3. tar xvzf apache-ant-1.8.4-bin.tar.gz
  4. sudo mv apache-ant-1.8.4 /opt/ant
  5. Set ANT_HOME=/opt/ant
  6. Add ‘export ANT_HOME=/opt/ant’ to /etc/profile

To verify that it worked, run:

ant -version
Brombomb
  • 6,988
  • 4
  • 38
  • 57
Kevin Driedger
  • 51,492
  • 15
  • 48
  • 55
  • 1
    Thanks - worked great. Is `/etc/profile` really the place to put the export? The comments in that file suggest that `/etc/profile.d/custom.sh` might be better (easier for package upgrades) – Nic Cottrell Jan 15 '14 at 11:38
  • 1
    Did you forget to add `export PATH="$ANT_HOME/bin:$PATH"`? Because otherwise you won't be able to run ant without declaring absolute path to `ant` binary. – likern Feb 06 '15 at 10:49
  • Adding an "ant.sh" to /etc/profile.d works on CentOS release 6.6 (Final) It's not necessary to add to your path if there is an existing version of ant already on it (at least 1.7.1 in my case) because the script uses ANT_HOME to find the jars to run. – gerardw Aug 12 '15 at 12:16