Like Maven, we could setup a repository server for better dependency management. So instead of connecting to the public repository, we want our Apache Ivy project links to our repository server, i have already setup the Artifactory repository server in my local machine. Let’s continue with the project we created yesterday.
1. Add the ivysettings.xml location in the build.xml.
<project name="hello-world-ant" basedir="." default="main" xmlns:ivy="antlib:org.apache.ivy.ant"> <!-- Ant properties --> <property name="src.dir" value="src"/> <property name="lib.dir" value="lib"/> <property name="build.dir" value="build"/> <property name="classes.dir" value="${build.dir}/classes"/> <property name="jar.dir" value="${build.dir}/jar"/> <property name="main-class" value="com.eureka.HelloWorld"/> <ivy:settings file="./ivysettings.xml" /> <target name="clean"> <delete dir="${build.dir}"/> <delete dir="${lib.dir}"/> </target> <target name="resolve"> <ivy:retrieve/> </target> <target name="report" depends="resolve"> <ivy:report todir="${build.dir}"/> </target> <target name="compile" depends="report"> <mkdir dir="${classes.dir}"/> <javac srcdir="${src.dir}" destdir="${classes.dir}"/> </target> <target name="jar" depends="compile"> <mkdir dir="${jar.dir}"/> <jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}"> <manifest> <attribute name="Main-Class" value="${main-class}"/> </manifest> </jar> </target> <target name="run" depends="jar"> <java jar="${jar.dir}/${ant.project.name}.jar" fork="true"/> </target> <target name="clean-build" depends="clean,jar"/> <target name="main" depends="clean,run"/> </project>
2. Create the ivysettings.xml.
<ivysettings> <settings defaultResolver="main" /> <credentials host="localhost" realm="Artifactory Realm" username="admin" passwd="password" /> <resolvers> <chain name="main"> <ibiblio name="public" m2compatible="true" root="http://localhost:8081/artifactory/repo" /> </chain> </resolvers> </ivysettings>
3. Try to build your project with Apache Ant and see if you could retrieve the dependencies from the Artifactory server.
Image may be NSFW.
Clik here to view.
4. Verify your setup by checking if the libs are cached on the Artifactory server.
Image may be NSFW.
Clik here to view.
Done =)
Reference: Setting up Ivy to work with Artifactory
Filed under: Ant, Apache Ivy Tagged: Ant, Apache Ivy, Artifactory, Java, Maven Image may be NSFW.
Clik here to view.
Clik here to view.
