ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nicolas LEHUEN <nicolas.leh...@ubicco.com>
Subject How to use a jar produced by a target as a classpath entry of ano ther target ?
Date Tue, 10 Apr 2001 20:13:03 GMT
Hi,

I'm looking for a way to create a jar file in a javac task in a target, and
use it as a classpath entry in another target.

Reusing the output of a javac task works perfectly when using files :

<target name="utils">
  <javac srcdir="${sources}" destdir="${build}/utils">
     <include name="utils/**"/>
  </javac>
  <jar jarfiles="${dist}/utils.jar" basedir="${build}/utils"/>
</target>

<target name="rest" depends="utils">
  <javac srcdir="${sources}" destdir="${build}/rest">
     <include name="rest/**"/>
     <classpath>
       <pathelement location="${build}/utils"/>
     </classpath>
  </javac>
  <jar jarfiles="${dist}/rest.jar" basedir="${build}/rest"/>
</target>

This is very useful as I can make sure that class dependencies of target
'rest' are matched against the result of target 'utils'. Thus, the file
rest.jar won't contain classes from the file utils.jar.

The problem is that dependencies between targets have to be written twice :
the first time in the 'depends' attribute, the second time in the classpath.
As my app features a lot of modules this is going to be tedious.

What I was planning to do is to insert all jars found in ${dist} into the
compilation classpath. This way, I should not have to write the dependencies
twice, but only once, as the result of the builf of each target would
automatically be found.

So I wrote :

<target name="rest" depends="utils">
  <javac srcdir="${sources}" destdir="${build}/rest">
     <include name="rest/**"/>
     <classpath>
        <fileset dir="${dist}">
           <include name="**/*.jar"/>
        </fileset>
     </classpath>
  </javac>
  <jar jarfiles="${dist}/rest.jar" basedir="${build}/rest"/>
</target>

But this does not work. The classes from utils.jar are not found, so the
compiler just recompile them, and I end up with duplicate classes in
utils.jar and rest.jar.

Does anybody know where I did something wrong ?

Regards,
-------------------------------------
Nicolas Lehuen
Head of R&D - Responsable R&D
Ubicco - http://www.ubicco.com
A FI System Company - http://www.fisystem.com
 <<Nicolas LEHUEN.vcf>> 

Mime
View raw message