ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dennis Putnam <>
Subject Including Maven Dependencies in Build
Date Thu, 06 Dec 2018 19:45:19 GMT
I have a working ant build script but I changed my application to use 
some maven dependencies. I am trying to include those dependencies into 
that build script. I found this article for doing that:

I know this article is old but I cannot find anything more recent that 
is the equivalent. If anyone has anything I would certainly be 
interested. Anyway as result I came up with this build.xml

<?xml version="1.0" encoding="UTF-8"?>
<project name="KCBSEvents" default="jar" basedir="." 
     <property name="" value=""/>
     <property name="resources" value="resource" />
     <property name="jardir" value="KCBSEvents" />
     <property name="KCBSDir" value="src/KCBSEvents" />
     <property name="member.number" value="000000" />
     <property name="" value="" />
     <path id="maven-ant-tasks.classpath" 
path="lib/maven-ant-tasks-2.1.3.jar" />
     <typedef resource="org/apache/maven/artifact/ant/antlib.xml"
            classpathref="maven-ant-tasks.classpath" />
     <target name="mvn-init">
         <echo message="Loading maven dependencies" />
         <artifact:dependencies filesetid="maven-dependencies">
             <dependency groupId="org.apache.httpcomponents" 
artifactId="httpclient" version="4.5.6" />
             <dependency groupId="commons-io" artifactId="commons-io" 
version="2.5" />
     <target name="checkOS">
         <condition property="isWindows">
             <os family="windows" />
         <condition property="isLinux">
             <os family="unix" />
     <target name="if_windows" depends="checkOS" if="isWindows">
         <property name="jarfile" value="C:\temp\KCBSEvents.jar" />
         <property name="antcontrib" value="H:\html\Applets\ant-contrib" />
     <target name="if_linux" depends="checkOS" if="isLinux">
         <property name="jarfile" 
value="/tmp/${member.number}/KCBSEvents.jar" />
         <property name="antcontrib" 
value="/var/www/html/Applets/ant-contrib/ant-contrib-1.0b3.jar" />
     <target name="setclass" depends="if_linux,if_windows">
         <taskdef resource="net/sf/antcontrib/">
                 <pathelement location="${antcontrib}" />
     <target name="incserial" depends="setclass">
         <copy todir="bin/${jardir}/${resources}">
             <fileset dir="${KCBSDir}/${resources}">
                 <include name="${}" />
                 <expandproperties />
         <if> <isset Property="build.number" /> <then>
             <echo message="update build requested" />
         </then> <else>
             <echo message="new build requested" />
             <buildnumber />
         </else> </if>
             <entry key="serialnumber" value="${build.number}" />
             <entry key="membernumber" value="${member.number}" />
             <entry key="name" value="${}" />
         <echo message="serial number: ${build.number}" />
     <target name="jar" description="Compile serialized jar" 
         <echo message="Using destination file ${jarfile}" />
         <javac srcdir="src" destdir="bin" 
classpathref="compile.classpath" includeantruntime="false" />
         <jar destfile="${jarfile}" basedir="bin">
                 <attribute name="Manifest-Version" value="1.0"/>
                 <attribute name="Created-By" value="1.6.0 (Sun 
Microsystems Inc.)" />
                 <attribute name="Main-Class" 
value="KCBSEvents.KCBSEvents" />

When I run ant I get a successful build. However, when I try to run the 
resulting jar file I get a traceback. The trackback seems to imply that 
the maven dependencies were not pulled into the jar. Am I missing 
something in the build that ties the dependencies to the jar? Can 
someone help me debug this? TIA.

FWIW here is the resulting output from the build:

Buildfile: /usr/build/makejar.xml





      [echo] update build requested
[propertyfile] Updating property file: 
      [echo] serial number: 1001

      [echo] Loading maven dependencies

      [echo] Using destination file /tmp/60286/KCBSEvents.jar
       [jar] Building jar: /tmp/60286/KCBSEvents.jar

Total time: 3 seconds

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message