ant - using fileset for classpath and copy task

A

Andrew McGhie

Hello,

I searched the groups and found a posting way back in 2003 which said
it couldn't be done, but I'm hoping more recent versions of ant this
is now possible. What I'm trying to do is declare a fileset once and
then reference it in my classpath and also copy the referenced jar
files to the root lib directory of my webapp. This is part of my
build.xml file:

Code:
<project>
  <!-- Hibernate Jars -->
  <fileset id="hibernate" dir="${hibernate.dir}">
    <filename name="lib/ant-antlr-1.6.5.jar" />
    <filename name="lib/antlr-2.7.6.jar" />
    <filename name="lib/asm.jar" />
    <filename name="lib/asm-attrs.jar" />
    <filename name="lib/cglib-2.1.3.jar" />
    <filename name="lib/commons-collections-2.1.1.jar" />
    <filename name="lib/commons-logging-1.0.4.jar" />
    <filename name="lib/dom4j-1.6.1.jar" />
    <filename name="hibernate3.jar" />
    <filename name="lib/jta.jar" />
    <filename name="lib/log4j-1.2.11.jar" />
  </fileset>
  ...
  <path id="classpath">
    <pathelement location="${servlet.jar}"/>
    <pathelement location="${jsp.jar}"/>
    <pathelement location="${jstl.jar}"/>
    <fileset refid="hibernate" />
  </path>
  ..
  <target name="populateDirectories" depends="makeDirectories">
    ...
    <copy todir="${build}/${appName}/WEB-INF/lib" verbose="true">
      <fileset refid="hibernate"/>
    </copy>
    ..
  </target>
</project>

This doesn't appear to work. Can someone help me in telling me what
I'm doing wrong?

Many Thanks

Andy
 
A

Andrew McGhie

Hello,

I searched the groups and found a posting way back in 2003 which said
it couldn't be done, but I'm hoping more recent versions of ant this
is now possible. What I'm trying to do is declare a fileset once and
then reference it in my classpath and also copy the referenced jar
files to the root lib directory of my webapp. This is part of my
build.xml file:

Code:
<project>
<!-- Hibernate Jars -->
<fileset id="hibernate" dir="${hibernate.dir}">
<filename name="lib/ant-antlr-1.6.5.jar" />
<filename name="lib/antlr-2.7.6.jar" />
<filename name="lib/asm.jar" />
<filename name="lib/asm-attrs.jar" />
<filename name="lib/cglib-2.1.3.jar" />
<filename name="lib/commons-collections-2.1.1.jar" />
<filename name="lib/commons-logging-1.0.4.jar" />
<filename name="lib/dom4j-1.6.1.jar" />
<filename name="hibernate3.jar" />
<filename name="lib/jta.jar" />
<filename name="lib/log4j-1.2.11.jar" />
</fileset>
...
<path id="classpath">
<pathelement location="${servlet.jar}"/>
<pathelement location="${jsp.jar}"/>
<pathelement location="${jstl.jar}"/>
<fileset refid="hibernate" />
</path>
..
<target name="populateDirectories" depends="makeDirectories">
...
<copy todir="${build}/${appName}/WEB-INF/lib" verbose="true">
<fileset refid="hibernate"/>
</copy>
..
</target>
</project>

This doesn't appear to work. Can someone help me in telling me what
I'm doing wrong?

Many Thanks

Andy

I figured it out, but I think it will only work with ant 1.7:

Code:
<project>
  ...
  <filelist id="hibernate" dir="${hibernate.dir}">
    <file name="lib/ant-antlr-1.6.5.jar" />
    <file name="lib/antlr-2.7.6.jar" />
    <file name="lib/asm.jar" />
    <file name="lib/asm-attrs.jar" />
    <file name="lib/cglib-2.1.3.jar" />
    <file name="lib/commons-collections-2.1.1.jar" />
    <file name="lib/commons-logging-1.0.4.jar" />
    <file name="lib/dom4j-1.6.1.jar" />
    <file name="hibernate3.jar" />
    <file name="lib/jta.jar" />
    <file name="lib/log4j-1.2.11.jar" />
  </filelist>
  ...
  <path id="classpath">
    <pathelement location="${servlet.jar}"/>
    <pathelement location="${jsp.jar}"/>
    <pathelement location="${jstl.jar}"/>
    <filelist refid="hibernate" />
  </path>
  ...
  <target name="populateDirectories" depends="makeDirectories">
    ...
    <copy todir="${build}/${appName}/WEB-INF/lib" verbose="true">
      <filelist refid="hibernate"/>
    </copy>
    ..
  </target>
</project>

Hope this helps
 
A

Andrew Thompson

(snip!)

Glad you sorted it.

...
Hope this helps

Solutions usually do help. Invariably others
will stumble over the same thing, but now a quick
search might reveal your answer.

It also helps to report that the problem is solved.
 
R

Roedy Green

I figured it out, but I think it will only work with ant 1.7:

another approach to tackling tough ant problems is to write a "stomp"
problem that generates your ant scripts. Then repetition or repeating
patterns are easy to handle with Java code.

It also makes it easier to maintain a set of scripts for all your
projects that are done in a consistent way. Any time you get smarter
about using ANT, it is instantly reflected in all your scripts.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top