ant - using fileset for classpath and copy task

Discussion in 'Java' started by Andrew McGhie, Feb 4, 2008.

  1. 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
    Andrew McGhie, Feb 4, 2008
    #1
    1. Advertising

  2. On Feb 4, 2:05 pm, Andrew McGhie <> wrote:
    > 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
    Andrew McGhie, Feb 5, 2008
    #2
    1. Advertising

  3. On Feb 5, 9:48 pm, Andrew McGhie <> wrote:

    (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.

    --
    Andrew T.
    Andrew Thompson, Feb 6, 2008
    #3
  4. Andrew  McGhie

    Roedy Green Guest

    On Tue, 5 Feb 2008 03:48:14 -0800 (PST), Andrew McGhie
    <> wrote, quoted or indirectly quoted someone
    who said :

    >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.
    --

    Roedy Green Canadian Mind Products
    The Java Glossary
    http://mindprod.com
    Roedy Green, Feb 7, 2008
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Miguel De Anda

    ant jar/fileset propblems

    Miguel De Anda, Jun 28, 2003, in forum: Java
    Replies:
    1
    Views:
    12,273
    Miguel De Anda
    Jul 3, 2003
  2. Replies:
    6
    Views:
    30,232
    Diplomat
    Jan 12, 2011
  3. Replies:
    1
    Views:
    5,297
    Tony Morris
    Mar 3, 2006
  4. krabhi
    Replies:
    1
    Views:
    9,262
    Marco Meschieri
    Aug 9, 2006
  5. Replies:
    2
    Views:
    4,502
    =?UTF-8?B?QXJuZSBWYWpow7hq?=
    Feb 10, 2007
Loading...

Share This Page