TestNG test cases are not compiling when i do project -> clean - eclipse

I am using Spring, TestNG, Eclipse, Maven, Mac OS
Scenario is
I am doing some changes in my test cases ( TestNG test cases ),
Then i do Project -> Clean in eclipse
Now i am running the test file, but the changes not updated.
I suspects that the test files are not compiled.
I can run the server and i can run my webservices
But if i run maven test ( mvn test ), the entire code is compiling including test cases.
So to run the test cases i am running mvn test command only.
Not able to run through eclipse.
Eclipse config:
Auto build on
In Java build path the test package is included
If you need any more info i'll provide.
org.testng.TestNGException:
Cannot find class in classpath: com.***.***.model.***.case.CaseModelImplTest
at org.testng.xml.XmlClass.loadClass(XmlClass.java:76)
at org.testng.xml.XmlClass.init(XmlClass.java:68)
at org.testng.xml.XmlClass.<init>(XmlClass.java:54)
at org.testng.xml.TestNGContentHandler.startElement(TestNGContentHandler.java:512)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:501)
at com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement(AbstractXMLDocumentParser.java:179)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.emptyElement(XMLDTDValidator.java:788)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.java:1343)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2755)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:511)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:808)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
at javax.xml.parsers.SAXParser.parse(SAXParser.java:395)
at javax.xml.parsers.SAXParser.parse(SAXParser.java:198)
at org.testng.xml.SuiteXmlParser.parse(SuiteXmlParser.java:17)
at org.testng.xml.SuiteXmlParser.parse(SuiteXmlParser.java:10)
at org.testng.xml.Parser.parse(Parser.java:170)
at org.testng.TestNG.initializeSuitesAndJarFile(TestNG.java:304)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:86)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:199)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:170)

It seems , you are not included your Test case class into the build path. Right click on your Project folder, go to the project properties->src
include your Testcase src folder by checking it.
Now it should run.

Open the Problems view. In Eclipse go to Window->Show View->Problems. It will list out all the failures while compiling the code.

Are the test cases being compiled, but to the wrong directory? They need to be compiled to test-classes not classes. In your build path, you need to set your Output folder to be
PROJECT/target/test-classes
This is true for all test resources (including src/test/java & src/test/resources).
Edit your project properties in Eclipse, select Java Build Path, and then in the Source tab, you'll see all of your source directories. Each one has an output folder. This output folder needs to be as above.

Go to Project --> Clean
That worked for me with similar problem.

Please check your testNG.xml file for correct test because I got the same error and it was because the wrong test name was entered.

is your test folder added as a source folder in Eclipse? If it isn't it won't be included in the build.

I solved this by:
Changing the build path / deleting some of the wrong ones
Cleaning the project

I think some time we get this error if your test class is in default package and in Testng.xml, you specify as below -
<suite name="Suite" parallel="none">
<listeners>
<listener class-name="org.uncommons.reportng.HTMLReporter" />
<listener class-name="org.uncommons.reportng.JUnitXMLReporter" />
</listeners>
<test name="Test">
<classes>
<class name=".Test1" />
</classes>
</test> <!-- Test -->
Here in above, I moved my testclass from default package to some package and also updated testng.xml as below - and everything started working.
<suite name="Suite" parallel="none">
<listeners>
<listener class-name="org.uncommons.reportng.HTMLReporter" />
<listener class-name="org.uncommons.reportng.JUnitXMLReporter" />
</listeners>
<test name="Test">
<classes>
<class name="com.sigma.rest.api.Test1" />
</classes>
</test> <!-- Test -->
I hope this helps you... if issue still exists, try above options.
thanks!

Check if your project artifacts like excel, property files, xml files etc are open in text editors etc. ( if yes please close them and do rebuild )
When you clean and rebuild make sure all project dependent files are closed and you do build.

Related

Eclipse/Grails - Tests don't run - ClassNotFoundException [duplicate]

While running junit test in eclipse I am getting this Exception:
java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing
I've added junit.jar library file.
I've tried different versions of junit.jar: 4.4, 4.8, etc.
How do I fix this Exception?
Add hamcrest-all-X.X.jar to your classpath.
Latest version as of Feb 2015 is 1.3:
http://code.google.com/p/hamcrest/downloads/detail?name=hamcrest-all-1.3.jar&can=2&q=
According to the JUnit GitHub team website (https://github.com/junit-team/junit/wiki/Download-and-Install), junit.jar and hamcrest-core.jar are both needed in the classpath when using JUnit 4.11.
Here is the Maven dependency block for including junit and hamcrest.
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.1.2</version>
<scope>test</scope>
</dependency>
<!-- Needed by junit -->
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
A few steps you have to follow:
Right click on the project.
Choose Build Path Then from its menu choose Add Libraries.
Choose JUnit then click Next.
Choose JUnit4 then Finish.
Works for me: IntelliJ IDEA 13.1.1, JUnit4, Java 6
I changed the file in project path: [PROJECT_NAME].iml
Replaced:
<library>
<CLASSES>
<root url="jar://$APPLICATION_HOME_DIR$/lib/junit-4.11.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
By:
<library name="JUnit4">
<CLASSES>
<root url="jar://$APPLICATION_HOME_DIR$/lib/junit-4.11.jar!/" />
<root url="jar://$APPLICATION_HOME_DIR$/lib/hamcrest-core-1.3.jar!/" />
<root url="jar://$APPLICATION_HOME_DIR$/lib/hamcrest-library-1.3.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
So the final .iml file is:
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/tests" isTestSource="true" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library">
<library name="JUnit4">
<CLASSES>
<root url="jar://$APPLICATION_HOME_DIR$/lib/junit-4.11.jar!/" />
<root url="jar://$APPLICATION_HOME_DIR$/lib/hamcrest-core-1.3.jar!/" />
<root url="jar://$APPLICATION_HOME_DIR$/lib/hamcrest-library-1.3.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
</component>
</module>
P.S.: save the file and don't let to IntelliJ Idea reload it. Just once.
You need junit-dep.jar because the junit.jar has a copy of old Hamcrest classes.
Just in case there's anyone here using netbeans and has the same problem, all you have to do is
Right click on TestLibraries
Click on Add Library
Select JUnit and click add library
Repeat the process but this time click on Hamcrest and the click add library
This should solve the problem
This problem is because of your classpath miss hamcrest-core-1.3.jar. To resolve this add hamcrest-core-1.3.jar as you add junit-4.XX.jar into your classpath.
At first, I encounter this problem too, but after I refer to the official site and add hamcrest-core-1.3.jar into classpath with command line, it works properly finally.
javac -d ../../../../bin/ -cp ~/libs/junit-4.12.jar:/home/limxtop/projects/algorithms/bin MaxHeapTest.java
java -cp ../../../../bin/:/home/limxtop/libs/junit-4.12.jar:/home/limxtop/libs/hamcrest-core-1.3.jar org.junit.runner.JUnitCore com.limxtop.heap.MaxHeapTest
You need to add the hamcrest-core JAR to the classpath as described here: https://github.com/junit-team/junit4/wiki/Download-and-Install
As a general rule, always make sure hamcrest is before any other testing libraries on the classpath, as many such libraries include hamcrest classes and may therefore conflict with the hamcrest version you're using. This will resolve most problems of the type you're describing.
the simplest way of solving the problem to begin with is copying latest version of hamcrest-code.jar into your CLASSPATH that is the file you store other .jar files needed for compilation and running of your application.
that could be e.g.: C:/ant/lib
It sounds like a classpath issue, so there are a few different ways to go about it. Where does org/hamcret/SelfDescribing come from? Is that your class or in a different jar?
Try going to your project Build Path and on the Libraries tab, add a Library. You should be able to choose JUnit to your project. This is a little bit different than just having the JUnit jar file In your project.
In your Run Configuration for the JUnit test, check the Classpath. You could probably fix this by adding making sure your Classpath can see that SelfDescribing class there. The Run option in Eclipse has a different set of options for the JUnit options.
If this problem arise in a RCP project it can be because JUnit has been explicitly imported.
Check the editor for your plugin.xml under Dependencies tab, remove the org.junit from the Imported Packages and add org.junit to the Required Plug-ins.
The problem is when you set up eclipse to point to JRE instead of JDK. JRE has junit4.jar in the lib/ext folder, but not hamcrest.jar :) So the solution is to check installed JREs in Eclipse, remove the existing one and create a new one pointing to your JDK.
This happens when you run Ant via command line. The implicit user dependencies are added in the classpath at the end and take precedence over the project-added classpath. Run Ant with -nouserlib flag. The implicit dependencies would be excluded from the classpath.
There is a better answer to solve this problem.
add dependency
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
The hamcrest-core-1.3.jar available on maven repository is deprecated.
Download working hamcrest-core-1.3.jar from official Junit4 github link .
If you want to download from maven repository, use latest hamcrest-XX.jar.
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
<version>2.2</version>
<scope>test</scope>
</dependency>
I had the same problem, the solution is to add in build path/plugin the jar org.hamcrest.core_1xx, you can find it in eclipse/plugins.
A few steps you have to follow:
Right click on the project.
Choose Build Path & then from its menu choose Add Libraries.
Choose JUnit then click Next.
Choose JUnit4 then Finish.
This works for me...
"java.lang.SecurityException: class" org.hamcrest.Matchers "'s signer information does not match signer information of other classes in the same package"
Do it:
Right-click on your package
click on Build Path -> Configure Build Path
Click on the Libraries tab
Remove JUnit
Apply and close
Ready.
Try adding the jar files manually or try with force update with the latest hamcrest.jar

Checkstyle Error in eclipse: cannot initialize module FilesFilter - Unable to instantiate FilesFilter

I am using checkstyle 5.7
I have written a custom FilesFilter as explained in the checkstyle documentation below,
http://checkstyle.sourceforge.net/writingfilters.html
As suggested in the documentation, I have written a java file and added an entry for it under "Checker" module in my config xml file.
So, this custom filter is supposed to ignore all files containing string "Test" in it's file name.
<module name="com.mycompany.myproject.filters.FilesFilter">
<property name="files" value="Test" />
</module>
Due to this entry in the config file, the check style is not loading in eclipse and gives following error,
cannot initialize module FilesFilter - Unable to instantiate
FilesFilter
Please help.
I think there is no straight solution for this yet. Or may be there is, if you are prepared to invest hours of your time.
Here's what I did as a workaround.
In eclipse, to disable checkstyles for a package (e.g. Test package in my case),
Go to, Project -> Properties -> Checkstyle
On Checkstyle Main tab, there is section "Exclude from checking.." with a set of check boxes.
Select the check box "files from packages:".
Click the "Change.." button in the right hand corner or just double click on "files from packages:"
Select the package you want Checkstyle to ignore. In my case I selected com/myproject/test/ package, and that was it. Checkstyle ignores all files in the test package.
If you are using Checkstyle as an ANT task, you may use excludes option as explained in the following code,
<target name="applyCheckStyle" depends="build" description="--> apply check style to all java files, excluding test package.">
<checkstyle config="${checkstyle.config}">
<fileset dir="${src.dir}" includes="**/*.java" excludes="**/test/**" />
<formatter type="plain" />
<formatter type="xml" toFile="${build.dir}/checkstyle_errors.xml" />
</checkstyle>
</target>
This worked for me :)

#CacheEvict annotation with SpEL works after Eclipse compile, but not after Ant compile

Problem
I have a class which uses Spring #CacheEvict annotations and embedded Spring Expression Language. When I allow this class to be compiled automatically by Eclipse, everything works fine. However, when I compile with an Ant task (either through Eclipse or from the command line), the resulting .class file doesn't work, and throws an Exception which seems like a red herring.
My question: How can I configure the Ant build so it generates working .class artifacts (so other developers can build my project without requiring Eclipse)? The configuration between Eclipse and Ant seem the same, but I must be missing some property somewhere.
Versions
Ant (bundled with Eclipse): org.apache.ant_1.8.3.v20120321-1730
Eclipse: Juno Service Release 1, 20120920-0800
JDK: 1.7.0_17
JUnit: 4.10 (in /lib/ of project)
O/S: Windows 7 64-bit
Spring: 3.2.2
Supporting Files
Because the problem is hard to describe without the project in front of you, I have boiled down my project to the bare minimum files needed to reproduce the issue:
/src/sample/SampleAction.java: Contains the method using the #CacheEvict annotation and SpEL.
package sample;
import org.springframework.cache.annotation.CacheEvict;
public class SampleAction {
#CacheEvict(value = "sampleCache", allEntries = true, condition = "#string.bytes != null")
public void triggerCache(String string) {
System.out.println("triggerCache(" + string + ")");
}
}
/src/sample/SampleActionTest.java: A unit test which works with Eclipse artifacts but fails with Ant artifacts.
package sample;
import org.junit.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
#RunWith(SpringJUnit4ClassRunner.class)
#ContextConfiguration(locations={"application.xml"})
public class SampleActionTest {
#Autowired
private SampleAction sampleAction;
#Test
public void testCacheMethod() {
sampleAction.triggerCache("Definitely not a null string.");
}
}
/src/sample/application.xml: Spring definition file for the caching and the action class.
<cache:annotation-driven />
<bean id="sampleAction" class="sample.SampleAction" />
<bean id="cacheManager" class="org.springframework.cache.support.SimpleCacheManager">
<property name="caches">
<set>
<bean class="org.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean" p:name="sampleCache" />
</set>
</property>
</bean>
/.settings/org.eclipse.jdt.core.prefs: Eclipse compiler settings (1.6 via 1.7.0_17):
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.6
/build.xml: The Ant build which cleans, compiles, and runs the unit test that fails.
<path id="classpath.main">
<fileset dir="lib" includes="*.jar" />
</path>
<path id="classpath.test">
<path refid="classpath.main" />
<pathelement location="output/classes" />
</path>
<target name="compileFailure" description="Cleans, compiles, and runs a unit test, which fails.">
<delete quiet="true" dir="output/classes" />
<mkdir dir="output/classes" />
<copy tofile="output/classes/sample/application.xml" file="src/sample/application.xml" />
<javac srcdir="src" destdir="output/classes"
classpathref="classpath.main" source="1.6" target="1.6" includeantruntime="false" />
<junit printsummary="yes">
<classpath refid="classpath.test" />
<formatter type="plain" usefile="false"/>
<test name="sample.SampleActionTest" outfile="result" />
</junit>
</target>
/lib/*.jar: Supporting libraries:
com.springsource.org.aopalliance-1.0.0.jar
commons-logging-1.1.3.jar
junit-4.10.jar
spring-aop-3.2.2.jar
spring-beans-3.2.2.jar
spring-context-3.2.2.jar
spring-context-support-3.2.2.jar
spring-core-3.2.2.jar
spring-expression-3.2.2.jar
spring-test-3.2.2.jar
This stub project is also available as a ZIP archive, including supporting JAR files for Spring and JUnit:
Minimal Eclipse Project
Steps to Reproduce
Open the "compilerDebug" project in Eclipse.
Allow Eclipse to automatically build the classes in the "sample" package. Either do a Project Clean/Build or open the Java files, edit the whitespace, and resave them. When compiled with Eclipse, output/classes/sample/SampleAction.class is 911 bytes.
Right-click on the "SampleActionTest" and choose "Run As... JUnit Test". Test passes successfully.
Open the build.xml file in the Ant view. Right-click on the "compileFailure" target and choose "Run As... Ant Build". Test fails with "EL1007E:(pos 0): Field or property 'bytes' cannot be found on null" stack trace. When compiled with Ant, output/classes/sample/SampleAction.class is 694 bytes.
Other Observations
I have tried adding compiler="org.eclipse.jdt.core.JDTCompilerAdapter" to the "javac" task, in order to force Ant to use the Eclipse compiler, but the unit test still fails after this change. SampleAction.class is 696 bytes here.
If I remove the condition from the #CacheEvict annotation, the unit test passes with both compilers.
Setting source/target levels to 1.5 or 1.7 has no effect.
Forcing the Ant task to "run in the same JRE as workspace" has no effect.
Downloading a standalone Ant distribution (1.9.1) and running the Ant build completely isolated from Eclipse has no effect.
Replacing the #CacheEvict annotation with declarative XML configuration (using aspectjtools) has no effect.
Thanks in advance for helping to prevent my inevitable insanity from troubleshooting.
Update
See answer provided below. Ant was not explicitly setting debug mode to true when compiling with javac. SpEL requires the extra debugging information to be included in the class files in order to correctly handle the annotations. Setting debug to true immediately corrected the issue.
<javac debug="true" [...] />
It seems like SpEL need java compiler to set debug information in class file to work. I had a similar problem that resolved after I enabled debugging info to be generated in maven build. Eclipse compiler does this automatically.

Ivy fails to resolve a dependency, unable to find cause

While using ivy:retrieve, it fails to resolve the dependency that should be downloaded. The output looks like this:
Buildfile: C:\Users\Simon\workspace\apollo\build.xml
init:
resolve:
BUILD FAILED
C:\Users\Simon\workspace\apollo\build.xml:42: 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:
-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
Total time: 348 milliseconds
The relevant section of the build.xml looks like so:
<target name="resolve" depends="init">
<ivy:retrieve pattern="${lib}/[artifact]-[revision].[ext]" sync="true" />
</target>
Here is also a list of what it should be downloading (from the build.xml)
<target name="doc" depends="build">
<javadoc sourcepath="${src}" classpathref="libraries" access="private" destdir="${doc}" windowtitle="Apollo">
<doclet name="org.jboss.apiviz.APIviz" pathref="libraries">
<param name="-sourceclasspath" value="${bin}" />
<param name="-author" />
<param name="-version" />
<param name="-use" />
<param name="-nopackagediagram" />
</doclet>
<doctitle><![CDATA[<h1>Apollo</h1>]]></doctitle>
<link href="http://download.oracle.com/javase/6/docs/api/" />
<link href="http://docs.jboss.org/netty/3.2/api/" />
<link href="http://guava-libraries.googlecode.com/svn/trunk/javadoc/" />
<link href="http://www.junit.org/apidocs/" />
<link href="http://commons.apache.org/compress/apidocs/" />
<link href="http://jruby.org/apidocs/" />
</javadoc>
</target>
ANT cannot find the ivy jar. Needs to be downloaded, extracted, and the ivy-x.y.z.jar 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.
If you can't put the ivy libs in the classpath for ant you will need to define it yourself:
<path id="ivy.lib.path">
<fileset dir="path/to/dir/with/ivy/jar" includes="*.jar"/>
</path>
<taskdef resource="org/apache/ivy/ant/antlib.xml"
uri="antlib:org.apache.ivy.ant" classpathref="ivy.lib.path"/>
This bit is missing from the getting started tutorial, but listed here: http://ant.apache.org/ivy/history/2.2.0/ant.html
When you Run Ant task, in the classpath ensure that ivy.jar is there. In the eclipse -> Run As-> Ant Build -> Edit configuration -> Classpath tab. Even though Eclipse would have the ivy.jar in the ANT Home, for some reason it's not called.
I had a similar problem on MacOSX (10.11.6 El Capitan). I installed ant and Ivy with the Brew package manager.
One additional way is to define it manually using the -lib option, e.g.:
ant clean compile -lib /usr/local/Cellar/ivy/2.4.0/libexec/ivy-2.4.0.jar
Even after adding ivy jar to the ant lib, it was not being picked up. Selecting the ANT_HOME again in Preferences->Ant->Runtime will cause the lib dir to be refreshed, and any libraries you have added there to be taken up.

Modify project build path with Apache Ant in Eclipse

I have an ant script that does the tipically: clean, compile, jar, javadocs, etc. I also have 3 projects in Eclipse: a library and 2 projects to test it.
In the build path of this 2 test projects I've defined as external jar the library jar located in the library project.
The library jar has its version in the jar name, i.e. library-0.1.jar. In the ant script I have a property with the version of the library:
<property name="project_version" value="0.1"/>
So to change the version I modify this property and run the script again. As you may deduce this generates a dependency error in the 2 other projects because they will still be pointing to an old file library-0.1.jar.
How can I change automatically the build path of that 2 other projects in Eclipse? Apache ant can do this with a specific tag?
Thanks.
Refer to the version with a variable in all your build files, e.g.
<include name="my-${version}.jar"/>
Now when you execute your builds, you can execute with explict version to match what you require, e.g.
ant -Dversion=1.3
Alternatively, you could load the same properties file in each of your build scripts to load the version property
<property file="version.properties">
Note that if you go with the latter you should remove the property declaration (from you post above) which sets the value explicitly. Either that or load the properties file first.
....
Use sed, e.g. (not tested):
version=2
sed s/value="\d+"/value="$version"/g build.xml
EDIT: Using the method below you will be able to compile using Ant, but eclipse will show you a dependency error in the project explorer because you don't have defined any external jar in the build path panel. To solve this you have to edit the .classpath file that you will see in the project root and add the following line:
<classpathentry kind="lib" path="../Library/bin"/>
Where Library is the folder for Library project and bin the folder for classes.
SOLVED:
I have to write an ant script for the 2 other projects and set the classpath with the script, not with eclipse IDE:
<path id="build-classpath">
<fileset dir="${dist}">
<include name="${project_name}-${project_version}.jar"/>
</fileset>
</path>
${dist} is the folder where is the jar library it's something like: "../Library/dist", where Library is the name of the project.
${project_name} and ${project_version} are loaded from a version.properties file that, again, is stored in "../Library":
<property file="..Library/version.properties"/>
The file version.properties just contains:
project_name=LibraryName
project_version=0.1
Then, to add the classpath when compiling...
<target name="compile" depends="clean, makedir">
<javac srcdir="${src}" destdir="${bin}">
<classpath refid="build-classpath"/>
</javac>
</target>
The refid value is the path id defined previously.