How to use wildcards in IVY: <artifacts pattern="..."/> - ivy

I want to publish my artifacts with ivy but my build path is dynamic and not static since it contains the version TAG i.e.: "build_02.14Test3".
This is from my build.xml:
<target name="go" depends="install-ivy"
description="--> create and publish">
<property environment="env"/>
<fail unless="env.PUBREVISION" message="no publish revision set!"/>
<ivy:resolve/>
<ivy:publish resolver="components" pubrevision="${env.PUBREVISION}">
<artifacts pattern="../Java/build_*/Release/[artifact].[ext]"/>
</ivy:publish>
</target>
The whole build.xml file:
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<project name="build-ivy" default="go" xmlns:ivy="antlib:org.apache.ivy.ant">
<!--
More information can be found at http://ant.apache.org/ivy/
-->
<!-- here is the version of ivy we will use. change this property to try a newer
version if you want -->
<property name="ivy.install.version" value="2.4.0" />
<property name="ivy.jar.dir" value="${basedir}/ivy" />
<property name="ivy.jar.file" value="${ivy.jar.dir}/ivy.jar" />
<property name="build.dir" value="build" />
<property name="src.dir" value="src" />
<target name="download-ivy" unless="skip.download">
<mkdir dir="${ivy.jar.dir}"/>
<!-- download Ivy from artifactory so that it can be used even without any special installation -->
<echo message="installing ivy..."/>
<get src="https://artifactory.company.com/artifactory/virtual-maven/org/apache/ivy/ivy/${ivy.install.version}/ivy-${ivy.install.version}.jar"
dest="${ivy.jar.file}" usetimestamp="true" username="svcbuild" password="**********************"/>
</target>
<!-- =================================
target: install-ivy
this target is not necessary if you put ivy.jar in your ant lib directory
if you already have ivy in your ant lib, you can simply remove this
target and the dependency the 'go' target has on it
================================= -->
<target name="install-ivy" depends="download-ivy" description="--> install ivy">
<!-- try to load ivy here from local ivy dir, in case the user has not already dropped
it into ant's lib dir (note that the latter copy will always take precedence).
We will not fail as long as local lib dir exists (it may be empty) and
ivy is in at least one of ant's lib dir or the local lib dir. -->
<path id="ivy.lib.path">
<fileset dir="${ivy.jar.dir}" includes="*.jar"/>
</path>
<taskdef resource="org/apache/ivy/ant/antlib.xml"
uri="antlib:org.apache.ivy.ant" classpathref="ivy.lib.path"/>
</target>
<!-- =================================
target: go
Go ivy, go!
================================= -->
<target name="go" depends="install-ivy"
description="--> create and publish">
<property environment="env"/>
<fail unless="env.PUBREVISION" message="no publish revision set!"/>
<ivy:resolve/>
<ivy:publish resolver="components" pubrevision="${env.PUBREVISION}">
<artifacts pattern="../Java/build_*/Release/[artifact].[ext]"/>
</ivy:publish>
</target>
<!-- =================================
target: clean
================================= -->
<target name="clean" description="--> clean the project">
<delete includeemptydirs="true" quiet="true">
<fileset dir="${src.dir}" />
<fileset dir="${build.dir}" />
</delete>
</target>
<!-- =================================
target: clean-ivy
================================= -->
<target name="clean-ivy" description="--> clean the ivy installation">
<delete dir="${ivy.jar.dir}"/>
</target>
<!-- =================================
target: clean-cache
================================= -->
<target name="clean-cache" depends="install-ivy"
description="--> clean the ivy cache">
<ivy:cleancache />
</target>
</project>
Basically all I wanna know is why my wildcard "*" is not working and how to fix it.
When running my pipeline I run into the issue that the wildcards are not recogniced:
[ivy:publish] :: delivering :: COMPANY#some.product;working#BUILD_PC :: 02.14Test11 :: integration :: Fri Feb 09 09:13:36 CET 2018
[ivy:publish] options = status=integration pubdate=Fri Feb 09 09:13:36 CET 2018 validate=true resolveDynamicRevisions=true merge=true resolveId=null pubBranch=null
[ivy:publish] delivering ivy file to D:\gr\builds\3d9e5594\0\plast\products\some.product\Java\build_*\Release\ivy.xml
BUILD FAILED
D:\gr\builds\3d9e5594\0\plast\products\some.product\ivy\build.xml:70: COMPANY#some.product;working#BUILD_PC: java.io.FileNotFoundException: D:\gr\builds\3d9e5594\0\plast\products\some.product\Java\build_*\Release\ivy.xml (The filename, directory name, or volume label syntax is incorrect)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.java:212)
at java.io.FileOutputStream.<init>(FileOutputStream.java:165)
at org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorUpdater.update(XmlModuleDescriptorUpdater.java:135)
at org.apache.ivy.core.deliver.DeliverEngine.deliver(DeliverEngine.java:207)
at org.apache.ivy.Ivy.deliver(Ivy.java:607)
at org.apache.ivy.ant.IvyDeliver.doExecute(IvyDeliver.java:420)
at org.apache.ivy.ant.IvyTask.execute(IvyTask.java:271)
at org.apache.ivy.ant.IvyPublish.doExecute(IvyPublish.java:308)
at org.apache.ivy.ant.IvyTask.execute(IvyTask.java:271)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:293)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:435)
at org.apache.tools.ant.Target.performTasks(Target.java:456)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1405)
at org.apache.tools.ant.Project.executeTarget(Project.java:1376)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1260)
at org.apache.tools.ant.Main.runBuild(Main.java:857)
at org.apache.tools.ant.Main.startAnt(Main.java:236)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:287)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:113)
Ivy.xml as requested (Note I replaced company and product names!) :
<ivy-module version="2.0">
<info organisation="MyOrganisation" module="Organisation.product" />
<publications>
<artifact name="Data1" ext="cab" type="binaries" />
<artifact name="Organisation product" ext="msi" type="binaries" />
<artifact name="setup" ext="exe" type="binaries" />
<artifact name="splash" ext="bmp" type="binaries" />
<artifact name="Java/jre-8u131-windows-i586" ext="exe" type="binaries" />
<artifact name="ProdA RemTool/Data1" ext="cab" type="binaries" />
<artifact name="ProdA RemTool/ProdA RemTool 01.36" ext="msi" type="binaries" />
<artifact name="ProdA RemTool/setup" ext="exe" type="binaries" />
<artifact name="ProdA RemTool/splash" ext="png" type="binaries" />
<artifact name="ProdA RemTool/viewsimba.splash" ext="bmp" type="binaries" />
</publications>
</ivy-module>

The solution to my problem was to fix the build path like this:
<artifacts pattern="../Java/build_${env.PUBREVISION}/Release/[artifact].[ext]"/>
since ${env.PUBREVISION}/ contains the TAG which is my build folder :)

Related

ant junit selenium wont run in jenkins

I have junit tests that use selenium to test web server.
When i run the tests using ant from command line, everything is working fine, browser gets opened and tests are going as planed.Browser gets open and i can see tests running.
Recently ive tried to add automatic tests as part of Ci cycle running on jenkins.
I run it as ant build command.
I can see that ant is executing properly (test classes are built i can see output from tests to console) but browser window never gets opened and test fails because of it. here is my ant file
<?xml version="1.0"?>
<project name="JUNIT" default="main" basedir="../../project" xmlns:artifact="antlib:org.apache.maven.artifact.ant">
<!-- Sets variables which can later be used. -->
<!-- The value of a property is accessed via ${} -->
<property name="api.dir" location="src/java" />
<property name="build.api.dir" location="target/classes" />
<property name="test.dir" location="src/test/java" />
<property name="build.test.dir" location="target" />
<!-- Variables used for JUnit testin -->
<property name="test.report.dir" location="testreport" />
<!-- Define the classpath which includes the junit.jar and the classes after compiling-->
<path id="api.class.path">
<pathelement location="${build.api.dir}" />
</path>
<artifact:dependencies cacheDependencyRefs="true" pathId="pomdeps.path">
<pom file="pom.xml"/>
</artifact:dependencies>
<target name="clean">
<delete dir="${test.report.dir}" />
<delete dir="${build.api.dir}" />
<delete dir="${build.test.dir}" />
</target> <!-- Creates the build, docs and dist directory-->
<target name="makedir">
<echo message="Make dir"/>
<mkdir dir="${build.test.dir}" />
<mkdir dir="${build.api.dir}" />
<mkdir dir="${test.report.dir}" />
</target> <!-- Compiles the java code (including the usage of library for JUnit -->
<target name="compile" depends="clean, makedir">
<echo message="Compile"/>
<javac srcdir="${api.dir}" destdir="${build.api.dir}" includeantruntime="false">
<!--classpath refid="junit.class.path" />
<classpath refid="libs.class.path" /-->
<classpath refid="pomdeps.path" />
</javac>
<javac srcdir="${test.dir}" destdir="${build.test.dir}" includeantruntime="false">
<!--classpath refid="junit.class.path" /-->
<classpath refid="api.class.path" />
<classpath refid="pomdeps.path" />
</javac>
</target>
<!-- Run the JUnit Tests --> <!-- Output is XML, could also be plain-->
<echo message="Classes folder ${build.test.dir}"/>
<target name="junit" depends="compile" >
<echo message="junit"/>
<junit printsummary="on" fork="false" haltonfailure="no" showoutput="true">
<classpath refid="pomdeps.path" />
<classpath>
<pathelement location="${build.test.dir}"/>
<pathelement location="${build.api.dir}"/>
</classpath>
<formatter usefile="false" type="plain"/>
<batchtest fork="no" todir="${test.report.dir}">
<fileset dir="${test.dir}">
<include name="**/*Test*.java"/>
</fileset>
</batchtest>
</junit>
</target>
<target name="main" depends="compile, junit">
<description>Main target</description>
</target>
</project>
Jenkins is 1.591 i installed it with default parameters as windows installation downloaded from their site.
Can it be something wrong with jenkins? Do i miss something?
As i mentioned earlier the problem was lack of UI permissions for Jenkins server.
1.configure Jenkins to run as service and make it login with real user name
2.Make sure that windows host that runs Jenkins logs on automaticaly after restart.

How to take back up of existing projects of remote server using ant

I am deploying my application using ant build script mention below. my application gets deployed on specified server mentioned in my ant script. but i want to take back of existing deployed project on remote server before i deployed new project. Here is my ant script.
<?xml version="1.0"?>
<project name="xyz" basedir="." default="deploy">
<!-- Read values from buildscript properties file -->
<property file="buildscript.properties" />
<!-- set global variable for this build -->
<property name="build" value="${basedir}/build"/>
<property name="src.dir" value="src"/>
<property name="build.dir" value="build"/>
<property name="classes.dir" value="${build.dir}/classes"/>
<property name="war.dir" value="${build.dir}/war"/>
<!-- Configure the context path for this application -->
<property name="path" value="/xyz"/>
<!-- set class path -->
<path id="compile.classpath">
<fileset dir="WebContent/WEB-INF/lib">
<include name="*.jar"/>
</fileset>
<fileset dir="${tomcatDir}">
<include name="*.jar"/>
</fileset>
</path>
<!-- Configure the custom Ant tasks for the Tomcat Server Manager -->
<taskdef name="deploy" classname="org.apache.catalina.ant.DeployTask">
<classpath refid="compile.classpath" />
</taskdef>
<taskdef name="undeploy" classname="org.apache.catalina.ant.UndeployTask">
<classpath refid="compile.classpath" />
</taskdef>
<taskdef name="start" classname="org.apache.catalina.ant.StartTask">
<classpath refid="compile.classpath" />
</taskdef>
<taskdef name="stop" classname="org.apache.catalina.ant.StopTask">
<classpath refid="compile.classpath" />
</taskdef>
<!-- delete build directory -->
<target name="clean">
<delete dir="${build.dir}"/>
</target>
<!-- create classes, war directory in build -->
<target name="create" depends="clean">
<mkdir dir="${classes.dir}"/>
<mkdir dir="${war.dir}"/>
</target>
<!-- compile source code and put classes in classes dir -->
<target name="compile" depends="create">
<copy todir="${classes.dir}" overwrite="true">
<fileset dir="src" excludes="*.java"/>
</copy>
<!-- for replacing cfg file to deploy on stagging-->
<copy todir="${classes.dir}" overwrite="true">
<fileset dir="${configurationFileDir}">
<include name="*.xml"/>
</fileset>
</copy>
<javac destdir="${classes.dir}" srcdir="${src.dir}" debug="true">
<classpath refid="compile.classpath"/>
</javac>
</target>
<!-- create war file -->
<target name="war" depends="compile">
<war destfile="${war.dir}/xyz.war" webxml="WebContent/WEB-INF/web.xml">
<fileset dir="WebContent"/>
<classes dir="build/classes"/>
</war>
</target>
<!-- Deploy war file -->
<target name="deploy" description="Install web application"
depends="war">
<deploy url="${url}" username="${username}" password="${password}"
path="${path}" war="file:${war.dir}/xyz.war"/>
</target>
<!-- Start apllication -->
<target name="start" description="start application in tomcat">
<start url="${url}" username="${username}" password="${password}" path="${path}"/>
</target>
<!-- Undeploy war file -->
<target name="undeploy" description="Remove web application" >
<undeploy url="${url}" username="${username}" password="${password}"
path="${path}"/>
</target>
<!-- Stop apllication -->
<target name="stop" description="stop application in tomcat">
<stop url="${url}" username="${username}" password="${password}" path="${path}"/>
</target>
</project>
The manager documentation describes a special tag attribute that can be used to redeploy your application:
URL parameters include:
update: When set to true, any existing update will be undeployed first....
tag: Specifying a tag name, this allows associating the deployed webapp
with a tag or label. If the web application is undeployed, it can be
later redeployed when needed using only the tag.
Unfortunately, the ANT task documentation does not describe any support for this attribute...
Interestingly, the Maven plugin does support this, but switching build tool would be a rather extreme solution to this problem :-)

Impossible to resolve dependencies in Ivy

I met a weird thing. I use ivy retrieve tag to put jar to somewhere.If I write code like below:
<target name="test">
<ivy:retrieve pattern="lib/[artifact](.[ext])" sync="true" type="jar" conf="webInfLib"/>
</target>
It work fine. But if I add something like below:
<target name="test">
<ivy:cachepath pathid="ivy.path" />
<ivy:retrieve pattern="lib/[artifact](.[ext])" sync="true" type="jar" conf="webInfLib"/>
</target>
It will throw "impossible to resolve dependencies". Any suggestions? Thanks.
Can't reproduce your problem. What version of ivy are using?
Example
Used the following software versions:
Apache Ant(TM) version 1.8.2
Apache Ivy 2.3.0-rc2
build.xml
<project name="demo" default="build" xmlns:ivy="antlib:org.apache.ivy.ant">
<target name="init" description="Use ivy to resolve classpaths">
<ivy:cachepath pathid="ivy.path" />
<ivy:retrieve pattern="lib/[artifact](.[ext])" sync="true" type="jar" conf="webInfLib"/>
</target>
<target name="build" depends="init" description="build project">
</target>
<target name="clean" description="Cleanup build files">
<delete dir="lib"/>
</target>
<target name="clean-all" depends="clean" description="Additionally purge ivy cache">
<ivy:cleancache/>
</target>
</project>
ivy.xml
<ivy-module version="2.0">
<info organisation="com.myspotontheweb" module="demo"/>
<configurations>
<conf name="webInfLib" description="add jar to web-inf/lib folder"/>
</configurations>
<dependencies>
<dependency org="javax.servlet" name="servlet-api" rev="2.4" conf="webInfLib->default"/>
</dependencies>
</ivy-module>

Ivy/Maven Resolve: Don't pull transitive "provided" jars

I'm using Ivy for my projects, but we're using Artifactory as our jar repository. I actually use <ivy:makepom> Ant task to create a Maven pom.xml, so I can deploy the jars and wars back to my Maven repository via the Maven deploy:deploy workflow.
I build a big jar called common-all.jar that requires about 30 jars for its compilation. I specify about 10 jars, and Ivy pulls down the dependencies. As part of the compile process, I specify the log4j jar, and some JBoss jars. These jars, of course, will be provided by our environment.
With this Jar, I also a bunch of wars. I specify the common-all.jar as part of my dependency, and the 30 jars that common-all.jar requires are also pulled down. All is well and good.
The problem is when I build the war. I do not want the JBoss jars or the log4j jars included as part of the war. These will be provided by the environment. I've marked them as provided in the pom.xml file. when I build common-all.jar.
Now, the question is how do I specify that I want these when I compile the code for the war, but I don't want to include them in my war itself.
Here's a sample of my ivy.xml file.
How can I specify that the common-all.jar requires certain specific jars for compilation, but when I build it in a war, I don't want all of these jars
<ivy-module version="1.0">
<info
organisation="com.travelclick"
module="TC-AppUtil"
revision="4.1"
status="release"/>
<configurations>
<conf name="default" visibility="public"
description="The single built artifact. Nothing else"/>
<conf name="compile" visibility="public"
description="The master module and transitive dependencies"/>
<conf name="provided" visibility="public"
description="Needed for compile. Will be provided outside or war"/>
<conf name="runtime" visibility="public"
description="Not required for compile, but for runtime"
extends="compile"/>
<conf name="default" visibility="public"
description="The default configuration"
extends="runtime"/>
<conf name="test" visibility="private"
description="Required for testing" extends="runtime"/>
</configurations>
<dependencies>
<!-- Normal Compile Dependencies -->
<dependency org="ximpleware" name="vtd-xml"
rev="2.5" conf="compile->default"/>
<dependency org="com.travelclick" name="common-all"
rev="4.1" conf="compile->compile,runtime"/>
<!-- Testing -->
<dependency org="junit" name="junit"
rev="4.10" conf="test->default"/>
</dependencies>
</ivy-module>
You haven't demonstrated how you declare the common-all dependency, so I'll make up the following example:
<dependency org="mygroup" name="common-all" rev="1.0" conf="compile->default;provided"/>
The magic is the configuration mapping:
The local "compile" configuration is mapped to the common module and its default (compile) scope dependencies, and
The local "provided" configuration is mapped to the common module and its provided scope dependencies.
Inside your build file the configurations are used as follows:
<project name="demo" default="build" xmlns:ivy="antlib:org.apache.ivy.ant">
<target name="resolve">
<ivy:resolve/>
<ivy:cachepath pathid="compile.path" conf="compile"/>
<ivy:cachepath pathid="provided.path" conf="provided"/>
</target>
<target name="compile" depends="resolve">
<javac ...
<classpath>
<path refid="compile.path"/>
<path refid="provide.path"/>
</classpath>
</javac>
</target>
<target name="build" depends="compile">
<ivy:retrieve pattern="build/lib/[artifact].[ext]" conf="runtime"/>
<war ...
<lib dir="build/lib"/>
</war>
</target>
<target name="clean">
<delete dir="build"/>
<ivy:cleancache/>
</target>
</project>

sample example which explain how to use filesystem resolver

Can anyone explain me how to use filesystem resolver in Ivy with sample by considering..
I have ivy.xml file where i have defined all the dependecies but i want the jars from my filesystem not from maven repository..?
where do i put ivysettings.xml file.
what build.xml should contain to use ivysettings.xml so that i can use jars from filesystem not from maven..
The ivysettings.xml file is located by default in the same directory as the ivy.xml file.
Alternative locations can be specified using the ivy settings task
Project structure
3rd party dependencies located in the lib directory.
$ tree
.
|-- build.xml
|-- ivysettings.xml
|-- ivy.xml
|-- lib
| |-- junit-4.10.jar
| |-- slf4j-api-1.6.4.jar
| `-- slf4j-simple-1.6.4.jar
`-- src
|-- main
| `-- java
| `-- org
| `-- demo
| `-- App.java
`-- test
`-- java
`-- org
`-- demo
`-- AppTest.java
10 directories, 8 files
ivy.xml
This ivy file uses configurations to manages 3 kinds of dependencies:
compile
runtime
test
These will correspond to the classpaths used by the ANT build.
<ivy-module version="2.0">
<info organisation="com.myspotontheweb" module="demo"/>
<configurations defaultconfmapping="compile->default">
<conf name="compile" description="Required to compile application"/>
<conf name="runtime" description="Additional run-time dependencies" extends="compile"/>
<conf name="test" description="Required for test only" extends="runtime"/>
</configurations>
<dependencies>
<!-- compile dependencies -->
<dependency org="org.slf4j" name="slf4j-api" rev="1.6.4"/>
<!-- runtime dependencies -->
<dependency org="org.slf4j" name="slf4j-simple" rev="1.6.4" conf="runtime->default"/>
<!-- test dependencies -->
<dependency org="junit" name="junit" rev="4.10" conf="test->default"/>
</dependencies>
</ivy-module>
ivysettings.xml
Nothing fancy. Simple mapping to the jars located in the lib directory:
<ivysettings>
<settings defaultResolver="local"/>
<resolvers>
<filesystem name="local">
<artifact pattern="${ivy.settings.dir}/lib/[artifact]-[revision].[ext]"/>
</filesystem>
</resolvers>
</ivysettings>
Alternatively..... I would always include the Maven central repo for non-local jars as follows:
<ivysettings>
<settings defaultResolver="central"/>
<resolvers>
<ibiblio name="central" m2compatible="true"/>
<filesystem name="local">
<artifact pattern="${ivy.settings.dir}/lib/[artifact]-[revision].[ext]"/>
</filesystem>
</resolvers>
<modules>
<module organisation="org.slf4j" resolver="local"/>
<module organisation="junit" name="junit" resolver="local"/>
</modules>
</ivysettings>
The modules section specifies which jars should be retrieved locally.
build.xml
Finally the build logic that uses ivy to manage the classpaths.
<project name="demo" default="build" xmlns:ivy="antlib:org.apache.ivy.ant">
<!--
================
Build properties
================
-->
<property name="src.dir" location="src/main/java"/>
<property name="test.src.dir" location="src/test/java"/>
<property name="build.dir" location="build"/>
<property name="classes.dir" location="${build.dir}/classes"/>
<property name="test.classes.dir" location="${build.dir}/test-classes"/>
<property name="ivy.reports.dir" location="${build.dir}/ivy-reports"/>
<property name="test.reports.dir" location="${build.dir}/test-reports"/>
<!--
===========
Build setup
===========
-->
<target name="init">
<ivy:resolve/>
<ivy:report todir='${ivy.reports.dir}' graph='false' xml='false'/>
<ivy:cachepath pathid="compile.path" conf="compile"/>
<ivy:cachepath pathid="runtime.path" conf="runtime"/>
<ivy:cachepath pathid="test.path" conf="test"/>
<mkdir dir="${classes.dir}"/>
<mkdir dir="${test.classes.dir}"/>
<mkdir dir="${test.reports.dir}"/>
</target>
<!--
===============
Compile targets
===============
-->
<target name="compile" depends="init">
<javac srcdir="${src.dir}" destdir="${classes.dir}" includeantruntime="false" debug="true" classpathref="compile.path"/>
</target>
<target name="compile-tests" depends="compile">
<javac srcdir="${test.src.dir}" destdir="${test.classes.dir}" includeantruntime="false" debug="true">
<classpath>
<path refid="test.path"/>
<pathelement path="${classes.dir}"/>
</classpath>
</javac>
</target>
<!--
============
Test targets
============
-->
<target name="test" depends="compile-tests">
<junit printsummary="yes" haltonfailure="yes">
<classpath>
<path refid="test.path"/>
<pathelement path="${classes.dir}"/>
<pathelement path="${test.classes.dir}"/>
</classpath>
<formatter type="xml"/>
<batchtest fork="yes" todir="${test.reports.dir}">
<fileset dir="${test.src.dir}">
<include name="**/*Test*.java"/>
<exclude name="**/AllTests.java"/>
</fileset>
</batchtest>
</junit>
</target>
<!--
=====================
Build and run targets
=====================
-->
<target name="build" depends="test"/>
<target name="run" depends="build">
<java classname="org.demo.App">
<classpath>
<path refid="runtime.path"/>
<pathelement location="${classes.dir}"/>
</classpath>
</java>
</target>
<!--
=============
Clean targets
=============
-->
<target name="clean">
<delete dir="${build.dir}"/>
</target>
<target name="clean-all" depends="clean">
<ivy:cleancache/>
</target>
</project>
If you're ONLY pulling jars locally and do not want to use Maven Central at all, Ivy is a waste of your time. Just put whatever jars you need in your /lib folder, add that to your classpath, and run your Ant file. Ivy is for interacting with Maven Central. However, if you need to do both, pull common jars from Maven and pull 3rd party jars from local, Mark's solution is a great one.