How to get Apache Ant to recognize Ivy

2

I'm trying to install Apache Ivy, but I can't get ant to recognize it.

Per Apache Ivy installation instructions, I downloaded Ivy from osuosl.org Ivy archives, unpacked it, and copied the .jar file to where ant should be able to see it. However, any ivy-dependent build I attempt fails as follows:

$ ant
Buildfile: /home/ec2-user/ivy/apache-ivy-2.3.0/build.xml

init-ivy:
  [taskdef] Could not load definitions from resource org/apache/ivy/ant/antlib.xml. It could not be found.

retrieve-all:

BUILD FAILED
/home/ec2-user/ivy/apache-ivy-2.3.0/build.xml:55: Problem: failed to create task or type antlib:org.apache.ivy.ant:retrieve
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.
No types or tasks have been defined in this namespace yet

This appears to be an antlib declaration. 
Action: Check that the implementing library exists in one of:
        -/usr/share/ant/lib
        -/home/ec2-user/.ant/lib
        -a directory added on the command line with the -lib argument

I've hunted around, and every page I look at seems to agree that I just need to "install the Ivy jar file", but this doesn't seem to help. I've tried:

  • Copying ivy-2.3.0.jar into /usr/share/ant/lib and/or ~/.ant/lib
  • The same, but renaming it ivy.jar
  • Adding -lib /path/to/ivy-2.3.0.jar to the ant command
  • All of this in the ivy directory or the src/example/hello-ivy directory

Interestingly, in the src/example/go-ivy directory, executing ant succeeds; but that doesn't help other ivy-based builds to run.

I must be missing something excruciatingly obvious, but I can't see what it is. Any ideas?

(This is on "Amazon Linux AMI release 2013.09")

Steve

Posted 2014-01-06T20:13:22.967

Reputation: 131

Answers

1

I wound up asking the same question on the Ivy users list, and got a response: http://mail-archives.apache.org/mod_mbox/ant-ivy-user/201402.mbox/%3C52FCAF1B.40903%40reast.net%3E. It turns out I simply needed to execute the following command before invoking ant:

export ANT_HOME=/usr/share/ant/

It appears that, while ant suggests placing files in /usr/share/ant/lib, it won't actually look there unless you set ANT_HOME.

Steve

Posted 2014-01-06T20:13:22.967

Reputation: 131

+1 You helped at least one person. It won't even look in ~/.ant/lib if this isn't defined. – user606723 – 2014-07-08T20:58:57.983

0

I have answered this question on Stackoverflow:

ivy fails to resolve a dependancy unable to find cause. I am including it inline below:


ANT cannot find the ivy jar. Needs to be placed into one of the following locations:

  • $ANT_HOME/lib
  • $HOME/.ant/lib

Enabling ivy

Ivy is packaged as an antlib, so to enable it you need to do the following

1) Declare the ivy namespace at the top of the build file

<project ..... xmlns:ivy="antlib:org.apache.ivy.ant">

2) Include the ivy jar in one of the ant library directories

Your error message indictates some of the possible locations for antlibs:

This appears to be an antlib declaration. 
Action: Check that the implementing library exists in one of:
        -C:\Users\Simon\eclipse\plugins\org.apache.ant_1.8.2.v20120109-1030\lib
        -C:\Users\Simon\.ant\lib
        -a directory added on the command line with the -lib argument

Note:

The beauty of an antlib is that you don't need to perform the taskdef (It's optional if you want to place the ivy jar in a non-standard location)

How to bootstrap a build

Even though ivy is an ANT sub-project, for some inexplicable reason ivy is not packaged with ANT....

I normally include the following target in my build files to setup a new environment:

<target name="bootstrap" description="Used to install the ivy task jar">
    <mkdir dir="${user.home}/.ant/lib"/>
    <get dest="${user.home}/.ant/lib/ivy.jar" src="http://search.maven.org/remotecontent?filepath=org/apache/ivy/ivy/2.2.0/ivy-2.2.0.jar"/>
</target>

It downloads the ivy jar from Maven Central.

Since all other ANT tasks can subsequently be downloaded using ivy, few people object to this little piece of ugliness at the top of the build file.

Mark O'Connor

Posted 2014-01-06T20:13:22.967

Reputation: 109

Thanks. I'd seen this answer, and it does describe the exact error message I'm getting, but the suggested fixes don't seem to help. Regarding (1), I'm even seeing this problem with Ivy sample projects such as apache-ivy-2.3.0/src/example/hello-ivy. The build.xml file for this sample project does contain the xmlns:ivy declaration. Regarding (2), I have tried everything I can think of to include the ivy jar, as described in my question. Do you have any further suggestions for determining why Ant is not recognizing the jar file? – Steve – 2014-01-13T01:37:53.823