Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > ant - using fileset for classpath and copy task

Reply
Thread Tools

ant - using fileset for classpath and copy task

 
 
Andrew McGhie
Guest
Posts: n/a
 
      02-04-2008
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
 
Reply With Quote
 
 
 
 
Andrew McGhie
Guest
Posts: n/a
 
      02-05-2008
On Feb 4, 2:05 pm, Andrew McGhie <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
 
Andrew Thompson
Guest
Posts: n/a
 
      02-06-2008
On Feb 5, 9:48*pm, Andrew McGhie <(E-Mail Removed)> 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.
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      02-07-2008
On Tue, 5 Feb 2008 03:48:14 -0800 (PST), Andrew McGhie
<(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Ant COPY task, want to copy the directory itself, not just its contents! dxd@ptc.com Java 6 01-12-2011 12:30 PM
Ant - <fileset> problem? tonywinslow1986@gmail.com Java 2 02-10-2007 06:35 PM
ANT: Howto process each file in fileset swebb99@gmail.com Java 1 03-03-2006 09:27 AM
Ant classpath modification for mail task moi Java 8 09-23-2005 09:36 PM
ant jar/fileset propblems Miguel De Anda Java 1 07-03-2003 10:57 PM



Advertisments