Download jars from nexus using the ant build tool, as done automatically in Maven

I have build.xml (ant based) that requires some jar from nexus to copy to an existing lib folder. ie, when he builds, he must copy the jar from nexus with a specific version, and then copy to lib and do the compilation. for example, in maven we define an artifact and its version. If the change will be automatically downloaded from maven repo. how can i do this in ant based strings?

Council of experts.

+4
source share
4 answers

I gave the example indicated in this thread one step further and created a macrodef to clean things up a bit for reuse. See below for downloading two artifacts from nexus (one snapshot, one release).

<project> <target name="get-all"> <mkdir dir="lib" /> <nexus-get groupId="foo.bar" artifactId="some-artifact" version="1.0.28" repo="releases" extension="jar" dest="lib" /> <nexus-get groupId="foo.bar" artifactId="another-artifact" version="1.0.0-SNAPSHOT" repo="snapshots" extension="jar" dest="lib" /> </target> <macrodef name="nexus-get"> <attribute name="groupId"/> <attribute name="artifactId"/> <attribute name="version"/> <attribute name="repo"/> <attribute name="extension"/> <attribute name="dest"/> <sequential> <get src="http://my-nexus:9999/nexus/service/local/artifact/maven/ redirect?r=@ {repo}&amp; g=@ {groupId}&amp; a=@ {artifactId}&amp; v=@ {version}&amp; e=@ {extension}" dest="@{dest}/@{artifactId} .@ {extension}" usetimestamp="true" /> </sequential> </macrodef> 

+7
source

You will probably be interested in Ivy . This is an Ant subproject for dependency management. It is ideal for your situation, because it can read Maven repositories and provides Ant tasks for loading published artifacts, creating class paths from them, etc. It supports your use case for using the latest version of the dependency if you configure it to request a revision of the "last.release" module.

+4
source

Although there are certain ways to combine ant and maven, the easiest thing is (if you know the link URL and your artifact settings to create the download URL), just use ant Get .

 <project name="MyProject" default="resolveDependencies" basedir="."> <target name="resolveDependencies"> <mkdir dir="lib" /> <get src="http://search.maven.org/remotecontent?filepath=log4j/log4j/1.2.9/log4j-1.2.9.jar" dest="lib/log4j-1.2.9.jar" usetimestamp="true" /> </target> </project> 
+3
source

Perhaps use Maven Ant Tasks .

As shown at http://maven.apache.org/ant-tasks/examples/dependencies.html Can list dependencies in ant, and also do things like copy them

I think the section Using FileSets and the Mapper version covers your needs.

You can use the filesId file, which will give you a link to a set of files that can be used to copy files to a specific location. For example, to populate WEB-INF / lib with your dependencies, you can use the following:

 <artifact:dependencies filesetId="dependency.fileset" useScope="runtime"> <dependency groupId="junit" artifactId="junit" version="3.8.2" scope="test"/> </artifact:dependencies> <copy todir="${webapp.output}/WEB-INF/lib"> <fileset refid="dependency.fileset" /> <!-- This mapper strips off all leading directory information --> <mapper type="flatten" /> </copy> 
0
source

All Articles