ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <>
Subject AW: Easier Way To Check and Install jars
Date Tue, 08 Jan 2008 06:05:51 GMT
> I wrote up a "short" install target in my ant file to make 
> sure I have  
> everything necessary to run script tasks, but it seems overly 
> verbose  
> for such a simple task:
>      <target name = "Copy-Jar" unless = "${JarName}.jar-exists" >

You cant use properties in the if/unless attribute of the target.

>          <echo message = "Installing ${JarName}.jar" />
>          <copy tofile = "/usr/share/ant/lib/${JarName}.jar" file =  
> "Tools/Ant/${JarName}.jar" />

You are installing ${JarName}.jar from a relative path ("Tools/..." =
"${basedir)/Tools") to 
an absolute location ("/usr/..."), right?

>      </target>
>      <target name = "Install-Jar" >
>          <available property = "${JarName}.jar-exists" file = "/usr/ 
> share/ant/lib/${JarName}.jar" type = "file" />

Just "improvements":

You should think about introducing a new property
	<property name="install.dir" location="/usr/share/ant/lib"/>
and use that
	<available property="${JarName}.jar-exists"
file="${install.dir}/${JarName}.jar" type="file"/>

>          <antcall target = "Copy-Jar" />
>      </target>
>      <target name = "install">
>          <antcall target = "Install-Jar" >
>              <param name = "JarName" value = "bsf" />
>          </antcall>

Using <macrodef> instead of <antcalls> would be better:
- convert the called target to <macrodef> (e.g. name="installJar")
- convert the <antcall>s to <installJar>

> I'm still somewhat new to ant, so I feel like I may be doing things  
> the hard way, is there any easier way to do this, namely one that  
> involves combining Install-Jar and Copy-Jar tasks?

Easier would be just to do a 

    <copy todir="/usr/share/ant/lib">
      <fileset dir="."

<copy> would check if the target file exists or is older than the copied
and skip copying if not.

You dont have to copy the ant-apache-bsf-1.7.0.jar as it should be
because it's part of the Ant distro.

Much more elegant would be using Ivy ... (I hope someone jumps in here


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

View raw message