Problem with Ant: Wildcard character expansion in command-line parametersof java application

Discussion in 'Java' started by Jari Kujansuu, Jun 2, 2005.

  1. Hi!

    First of all I am using Ant version 1.6.2 (both Windows and Linux).

    I am trying to execute java application as a part of the ant build.
    This java application should receive couple of files as command-line
    parameters. These files might vary and I would like to make a generic
    ant task using wildcard characters so that I don't need to start
    maintaining build.xml file every time when new file is taken into use.

    What I would like to achieve is an ant task that would do corresponding
    thing as following command-line example

    java -cp . MyJavaApp *.xml

    So here is the ant task I made

    <target name="runMyJavaApp">
    <java classname="MyJavaApp">
    <classpath>
    <pathelement location="."/>
    </classpath>
    <arg value="*.xml" />
    </java>
    </target>

    The problem is wildcard character expansion. Above example does not
    expand wildcard character * used in arg element and thus MyJavaApp
    gets literally *.xml as command-line parameter when it should really
    get something like a.xml b.xml c.xml ...

    Then I accidentally notice that if I used fork="yes" attribute in java
    task then wildcard expansion works in Windows but not in Linux. Like
    this

    <java classname="MyJavaApp" fork="yes">
    ...
    </java>

    I need to run ant build both in Linux and Windows so above solution is
    not acceptable.

    So has anyone else encoutered same kind of problem earlier and
    especially found a solution to it? I would expect that using wildcard
    characters would be so common situation that there must be a way to do
    it correctly. Or is there some reason why this is not possible in Ant?
    Wildcard characters can be used in other places for example in classpath
    when building java code. So why it does not work in command-line
    arguments?

    --
    Jari Kujansuu
    Nokia Networks
    P.O. Box 785, 33101 Tampere, Finland
    Hatanpään valtatie 30 / C379.2, 3. floor
    E-mail:
    Phone: work: +358 (0)7180 74154 mobile: +358 50 4868 538
    Jari Kujansuu, Jun 2, 2005
    #1
    1. Advertising

  2. Jari Kujansuu

    Juha Laiho Guest

    Jari Kujansuu <> said:
    >First of all I am using Ant version 1.6.2 (both Windows and Linux).
    >
    >I am trying to execute java application as a part of the ant build.

    ....
    >The problem is wildcard character expansion. Above example does not
    >expand wildcard character * used in arg element and thus MyJavaApp
    >gets literally *.xml as command-line parameter when it should really
    >get something like a.xml b.xml c.xml ...
    >
    >Then I accidentally notice that if I used fork="yes" attribute in java
    >task then wildcard expansion works in Windows but not in Linux.


    I'll hazard a guess as to why this is so. No solutions, though, but
    perhaps this helps in finding one.

    In Windows (or DOS, for that matter), expanding wildcard filename arguments
    has been the task of the application receiving the arguments. So, each
    application has contained code to handle wildcards in arguments.

    In Unix (and like) systems, wildcard expansion has been a task for the
    shell interpreting the commands.

    When you start a task with 'fork="yes"' in ant, it'll just start the
    requested task, but not a separate shell. Thus, in Windows, the
    started task (process) will handle the wildcard expansion, but in
    Linux, as shell is not started, there's nothing to expand the
    wildcards.
    --
    Wolf a.k.a. Juha Laiho Espoo, Finland
    (GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
    PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
    "...cancel my subscription to the resurrection!" (Jim Morrison)
    Juha Laiho, Jun 2, 2005
    #2
    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. TC
    Replies:
    1
    Views:
    9,851
    Ryan Stewart
    May 23, 2004
  2. Burt
    Replies:
    1
    Views:
    677
    vahan
    Jul 14, 2006
  3. Replies:
    7
    Views:
    819
  4. Michael Jia
    Replies:
    13
    Views:
    377
    Paul Denize
    Jun 16, 2009
  5. Perl wildcard un-expansion

    , Nov 19, 2007, in forum: Perl Misc
    Replies:
    4
    Views:
    122
Loading...

Share This Page