ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <Jan.Mate...@rzf.fin-nrw.de>
Subject AW: Convert fileset into command-line args, allowing for spaces in directori
Date Tue, 24 Jan 2006 07:35:59 GMT
Ok, I´ve done some tests...

App.java just print the given arguments.
The buildfile compiles that and uses several different invocations for that
application with a "path" as "argument"

Maybe we dont know exactly what you want to achieve, but I´m sure you get
your solution here ;-)


Jan



App.java
---8-<-------8-<-------8-<-------8-<-------8-<-------8-<-------8-<-------8-<----
public class App {
    public static void main(String[] args) {
        System.out.println("args (" + args.length + ")");
        for (int i=0; i<args.length; i++) {
            System.out.println("  " + i + ": " + args[i]);
        }
    }
}
---8-<-------8-<-------8-<-------8-<-------8-<-------8-<-------8-<-------8-<----




Directory Layout
---8-<-------8-<-------8-<-------8-<-------8-<-------8-<-------8-<-------8-<----
C:.
|   App.class
|   App.java
|   build.xml
|
\---files
        with a space.file
        withoutaspace.file
---8-<-------8-<-------8-<-------8-<-------8-<-------8-<-------8-<-------8-<----


build.xml
---8-<-------8-<-------8-<-------8-<-------8-<-------8-<-------8-<-------8-<----
<project>

    <javac srcdir="." destdir="."/>


    <path id="p">
        <pathelement location="files/with a space.file"/>
        <pathelement location="files/withoutaspace.file"/>
    </path>



    <!-- all elements in ONE string
    args (1)
      0: C:\tmp\ant-javaWithPath\files\with a space.file;C:\tmp\ant-javaWithPath\files\withoutaspace.file
    -->
    <java classname="App" classpath=".">
        <arg pathref="p"/>
    </java>    


    <!-- all in ONE string and then split on spaces
    args (3)
      0: C:\tmp\ant-javaWithPath\files\with
      1: a
      2: space.file;C:\tmp\ant-javaWithPath\files\withoutaspace.file
    -->
    <property name="p2" refid="p"/>
    <java classname="App" classpath=".">
        <arg line="${p2}"/>
    </java>    


    <!-- each path element in its own variable; on several threads 
    args (1)
      0: C:\tmp\ant-javaWithPath\files\with a space.file
    args (1)
      0: C:\tmp\ant-javaWithPath\files\withoutaspace.file
    -->
    <apply executable="java">
        <arg line="-classpath ."/>
        <arg value="App"/>
        <path refid="p"/>
    </apply>


    <!-- each path element in its own variable; in one application 
    args (2)
      0: C:\tmp\ant-javaWithPath\files\with a space.file
      1: C:\tmp\ant-javaWithPath\files\withoutaspace.file
    -->
    <pathconvert property="p3" refid="p"
        pathsep="&quot; &quot;"
    />
    <property name="p4" value="&quot;${p3}&quot;"/> 
    <java classname="App" classpath=".">
        <arg line="${p4}"/>
    </java>    


</project>
---8-<-------8-<-------8-<-------8-<-------8-<-------8-<-------8-<-------8-<----

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message