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

J

Jari Kujansuu

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: (e-mail address removed)
Phone: work: +358 (0)7180 74154 mobile: +358 50 4868 538
 
J

Juha Laiho

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top