Java Mailing List Archive

http://www.ant-tasks.com/

Apache Ant Archive

» Ant Users List
» Ant Developers List
Copy jars mensioned in classpath

Copy jars mensioned in classpath

2003-03-24       - By Dominique Devienne
Reply:     1     2     3     4     5  

It's a little bit convoluted, but the <script> below works...
Can <copy> or <delete> a Path reference. --DD



P:\org_apache\antx>C:\pro\ant1.5.1\bin\ant -f copy-delete-path-script.xml
clean
Buildfile: copy-delete-path-script.xml

clean:
  [delete] Deleting directory P:\org_apache\antx\CopyDeletePath

BUILD SUCCESSFUL
Total time: 1 second
P:\org_apache\antx>C:\pro\ant1.5.1\bin\ant -f copy-delete-path-script.xml
copy-path
Buildfile: copy-delete-path-script.xml

init:
    [echo] path = C:\pro\ant1.5.1\lib\ant-contrib-0.1.jar
    [echo]        C:\pro\ant1.5.1\lib\ant.jar
    [echo]        C:\pro\ant1.5.1\lib\bsf.jar
    [echo]        C:\pro\ant1.5.1\lib\js.jar
    [echo]        C:\pro\ant1.5.1\lib\junit.jar
    [echo]        C:\pro\ant1.5.1\lib\optional.jar
    [echo]        C:\pro\ant1.5.1\lib\pmd-1.01.jar
    [echo]        C:\pro\ant1.5.1\lib\which.jar
    [echo]        C:\pro\ant1.5.1\lib\xercesImpl.jar
    [echo]        C:\pro\ant1.5.1\lib\xml-apis.jar

copy-path:
   [mkdir] Created dir: P:\org_apache\antx\CopyDeletePath

-add-path-element-to-task:

-copy-path:
    [copy] Copying 10 files to P:\org_apache\antx\CopyDeletePath

BUILD SUCCESSFUL
Total time: 1 second
P:\org_apache\antx>dir CopyDeletePath
Volume in drive P has no label.
Volume Serial Number is AC70-F961

Directory of P:\org_apache\antx\CopyDeletePath

03/24/2003  11:19a      <DIR>          .
03/24/2003  11:19a      <DIR>          ..
03/24/2003  11:19a               9,324 ant-contrib-0.1.jar
03/24/2003  11:19a             717,666 ant.jar
03/24/2003  11:19a             105,573 bsf.jar
03/24/2003  11:19a             390,767 js.jar
03/24/2003  11:19a             121,070 junit.jar
03/24/2003  11:19a             654,735 optional.jar
03/24/2003  11:19a             484,480 pmd-1.01.jar
03/24/2003  11:19a              17,193 which.jar
03/24/2003  11:19a             831,473 xercesImpl.jar
03/24/2003  11:19a             108,484 xml-apis.jar
             10 File(s)      3,440,765 bytes
              2 Dir(s)   6,337,785,856 bytes free

P:\org_apache\antx>C:\pro\ant1.5.1\bin\ant -f copy-delete-path-script.xml
delete-path
Buildfile: copy-delete-path-script.xml

delete-path:
    [echo] jars2delete =
P:\org_apache\antx\CopyDeletePath\ant-contrib-0.1.jar
    [echo]            P:\org_apache\antx\CopyDeletePath\ant.jar
    [echo]            P:\org_apache\antx\CopyDeletePath\bsf.jar
    [echo]            P:\org_apache\antx\CopyDeletePath\js.jar
    [echo]            P:\org_apache\antx\CopyDeletePath\junit.jar
    [echo]            P:\org_apache\antx\CopyDeletePath\optional.jar
    [echo]            P:\org_apache\antx\CopyDeletePath\pmd-1.01.jar
    [echo]            P:\org_apache\antx\CopyDeletePath\which.jar
    [echo]            P:\org_apache\antx\CopyDeletePath\xercesImpl.jar
    [echo]            P:\org_apache\antx\CopyDeletePath\xml-apis.jar

-add-path-element-to-task:

-delete-path:
  [delete] Deleting 1 files from P:\org_apache\antx\CopyDeletePath
  [delete] Deleting 1 files from P:\org_apache\antx\CopyDeletePath
  [delete] Deleting 1 files from P:\org_apache\antx\CopyDeletePath
  [delete] Deleting 1 files from P:\org_apache\antx\CopyDeletePath
  [delete] Deleting 1 files from P:\org_apache\antx\CopyDeletePath
  [delete] Deleting 1 files from P:\org_apache\antx\CopyDeletePath
  [delete] Deleting 1 files from P:\org_apache\antx\CopyDeletePath
  [delete] Deleting 1 files from P:\org_apache\antx\CopyDeletePath
  [delete] Deleting 1 files from P:\org_apache\antx\CopyDeletePath
  [delete] Deleting 1 files from P:\org_apache\antx\CopyDeletePath

BUILD SUCCESSFUL
Total time: 1 second
P:\org_apache\antx>dir CopyDeletePath
Volume in drive P has no label.
Volume Serial Number is AC70-F961

Directory of P:\org_apache\antx\CopyDeletePath

03/24/2003  11:21a      <DIR>          .
03/24/2003  11:21a      <DIR>          ..
              0 File(s)              0 bytes
              2 Dir(s)   6,341,246,976 bytes free

P:\org_apache\antx>type copy-delete-path-script.xml
<?xml version="1.0"?>

<!-- ANT build file to test a specific feature or bug of ANT.
    Dominique Devienne <ddevienne@(protected)>         Mar 2003
 -->
<project name="CopyDeletePath" default="init">

 <target name="init">
   <!-- Simulate user-supplied Path -->
   <path id="path">
     <fileset dir="${ant.home}/lib" includes="*.jar" />
   </path>
   <property name="path" refid="path" />

   <!-- Pretty print path-->
   <pathconvert property="formatted-path" refid="path"
                pathsep="${line.separator}       " />
   <echo message="path = ${formatted-path}" />
 </target>

 <target name="clean">
   <delete dir="${ant.project.name}" quiet="true" />
 </target>

 <target name="copy-path" depends="init">
   <mkdir dir="${ant.project.name}" />
   <antcall target="-copy-path">
     <param name="taskid" value="copy" />
     <reference refid="path" torefid="path2add" />
   </antcall>
 </target>

 <target name="-copy-path" depends="-add-path-element-to-task">
   <copy id="copy" todir="${ant.project.name}" />
 </target>

 <target name="delete-path">
   <mkdir dir="${ant.project.name}" />
   <path id="jars2delete">
     <fileset dir="${ant.project.name}" includes="*.jar" />
   </path>
   <property name="jars2delete" refid="jars2delete" />
   <pathconvert property="formatted-path2" refid="jars2delete"
                pathsep="${line.separator}           " />
   <echo message="jars2delete = ${formatted-path2}" />

   <antcall target="-delete-path">
     <param name="taskid" value="delete" />
     <reference refid="jars2delete" torefid="path2add" />
   </antcall>
 </target>

 <target name="-delete-path" depends="-add-path-element-to-task">
   <delete id="delete" quiet="true" />
 </target>

 <target name="-add-path-element-to-task">
   <script language="javascript"><![CDATA[
     prj  = self.getProject();
     task = prj.getReference(prj.getProperty("taskid"));
     path = prj.getReference("path2add");
     importPackage(Packages.org.apache.tools.ant.types);
     jars = path.list();
     for (var i = 0; i < jars.length; ++i) {
       fileset = new FileSet();
       fileset.setProject(prj);
       fileset.setFile(new java.io.File(jars[i]));
       task.addFileset(fileset);
     }
   ]]></script>
 </target>

</project>

P:\org_apache\antx>

-----Original Message-----
From: "Schaible, J?rg" [mailto:Joerg.Schaible@(protected)]
Sent: Monday, March 24, 2003 10:43 AM
To: Ant Users List
Subject: RE: [newbie] Copy jars mensioned in classpath

Hi Dominique,

> From: Dominique Devienne
>
> I'm afraid not directly.... At least I can't think of one. In your
> situation, I'd write a <script> that creates that populates a
> copy tasks
> with every file of a Path, feeding a <fileset
> file="thefile"/> for each
> entry in Path#list() to <copy> (which accepts several filesets).

possibly there is a better way to define the paths. Originally
I tried to define something like


foo.jar.foo1=${foo.dir}/foo1.jar
foo.jar.foo2=${foo.dir}/foo2.jar
foo.jars=${foo.jar.foo1} ${foo.jar.foo2}

bar.jar.bar=${bar.dir}/bar.jar
bar.jars=${bar.jar.bar}


but I was not able to create a classpath from ${bar.jars} and
${foo.jars}, since the path element treats the entries with
multiple jar files as single element. Maybe someone knows a
better solution for this ?

Regards,
J?rg

> -----Original Message-----
> From: "Schaible, J?rg"
> Sent: Monday, March 24, 2003 5:40 AM
> To: Ant Users List
> Subject: [newbie] Copy jars mensioned in classpath
>
> Hi,
>
> my application is based on several other Java libraries.
> These are defined
> in an
>  external property file, e.g.
>
> foo.jar.foo1=${foo.dir}/foo1.jar
> foo.jar.foo2=${foo.dir}/foo2.jar
> foo.path=${foo.jar.foo1}:${foo.jar.foo2}
>
> bar.jar.bar=${bar.dir}/bar.jar
> bar.path=${bar.jar.bar}
>
> you got the pattern ...
>
> In the build.xml I am now able to use this definitions like:
>
>
>   <path id="classpath">
>     <pathelement path="${foo.path}" />
>     <pathelement path="${bar.path}" />
>   </path>
>
>   <target name="compile">
>     <mkdir dir="${build.dir}" />
>     <javac srcdir="${src.java}"
>           destdir="${build.dir}"
>         classpathref="classpath" >
>     </javac>
>   </target>
>
>
> Works fine.
>
> Now I want to copy the jars used in the classpath to a distribution
> directory,
> but I did not find a solution using the copy-task to define a
> fileset based
> on
> the definitions made above, since every definition could
> contain more than
> one
> jar file separated by a colon. Is there any task or a fileset
> construct,
> that
> enables me to get the jars from the involved classpath in a fileset?
> Regards,
> J?rg
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@(protected)
> For additional commands, e-mail: user-help@(protected)
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@(protected)
For additional commands, e-mail: user-help@(protected)


©2008 ant-tasks.com - Jax Systems, LLC, U.S.A.