Discussion:
macrodef with parameters to pass to java task
Al Le
2017-05-29 10:04:52 UTC
Permalink
Hello,

in my ant script I'd like to define a macro (via macrodef) which would call the 'java' task as a part of its body/implementation.

In the java task call in the macro, I want to just specify the main class name and the classpath. The parameters (which are usually specified via nested 'arg' elements) should be as variable as they are in the original java task.

How would I accomplish this?

What I've come up with until now is:

<macrodef name="execMyProgram">
<element name="programArgs" implicit="true" description="'arg' entries for the program, use like in the java task"/>

<sequential>
<java classname="my.class.name" classpathref="my.classpath">
<programArgs/>
</java>
</sequential>
</macrodef>



Then I use the macro as follows:

<execMyProgram>
<programArgs>
<arg value="arg1"/>
<arg value="arg2"/>
</programArgs>
</executeProcessMonitor>


But I get the error message: The <java> type doesn't support the nested "programArgs" element.

Thank you for the help!

AL

---------------------------------------------------------------------
To unsubscribe, e-mail: user-***@ant.apache.org
For additional commands, e-mail: user-***@ant.apache.org
Al Le
2017-05-29 10:13:59 UTC
Permalink
I'm sorry, the last closing tag in the example should of course be "</execMyProgram>".
Gesendet: Montag, 29. Mai 2017 um 12:04 Uhr
Betreff: macrodef with parameters to pass to java task
Hello,
in my ant script I'd like to define a macro (via macrodef) which would call the 'java' task as a part of its body/implementation.
In the java task call in the macro, I want to just specify the main class name and the classpath. The parameters (which are usually specified via nested 'arg' elements) should be as variable as they are in the original java task.
How would I accomplish this?
<macrodef name="execMyProgram">
<element name="programArgs" implicit="true" description="'arg' entries for the program, use like in the java task"/>
<sequential>
<java classname="my.class.name" classpathref="my.classpath">
<programArgs/>
</java>
</sequential>
</macrodef>
<execMyProgram>
<programArgs>
<arg value="arg1"/>
<arg value="arg2"/>
</programArgs>
</executeProcessMonitor>
But I get the error message: The <java> type doesn't support the nested "programArgs" element.
Thank you for the help!
AL
---------------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: user-***@ant.apache.org
For additional commands, e-mail: user-***@ant.apache.org
Stefan Bodewig
2017-05-29 10:16:55 UTC
Permalink
Post by Al Le
in my ant script I'd like to define a macro (via macrodef) which would call the 'java' task as a part of its body/implementation.
In the java task call in the macro, I want to just specify the main class name and the classpath. The parameters (which are usually specified via nested 'arg' elements) should be as variable as they are in the original java task.
How would I accomplish this?
<macrodef name="execMyProgram">
<element name="programArgs" implicit="true" description="'arg' entries for the program, use like in the java task"/>
<sequential>
<java classname="my.class.name" classpathref="my.classpath">
<programArgs/>
</java>
</sequential>
</macrodef>
This is the correct way to do it. "implicit=true" means any element you
nest into <execMyProgram> later will get collected as child of your
<programArgs> element and you don't need to use that element name
explicitly.

So instead of
Post by Al Le
<execMyProgram>
<programArgs>
<arg value="arg1"/>
<arg value="arg2"/>
</programArgs>
</executeProcessMonitor>
you only have to use

<execMyProgram>
<arg value="arg1"/>
<arg value="arg2"/>
</executeProcessMonitor>

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: user-***@ant.apache.org
For additional commands, e-mail: user-***@ant.apache.org
Jan Matèrne (jhm)
2017-05-29 10:59:33 UTC
Permalink
With that macro definition you also could use the other available nested
elements:

<execMyProgram>
<!-- examples from <java> -->
<arg value="arg1"/>
<jvmarg value="-Xrunhprof:cpu=samples,file=log.txt,depth=3"/>
<sysproperty key="DEBUG" value="true"/>
<classpath>
<pathelement location="dist/test.jar"/>
<pathelement path="${java.class.path}"/>
</classpath>
<!-- example from <exec> -->
<redirector outputproperty="redirector.out"
errorproperty="redirector.err"
inputstring="blah before blah">
<inputfilterchain>
<replacestring from="before" to="after"/>
</inputfilterchain>
<outputmapper type="merge" to="redirector.out"/>
<errormapper type="merge" to="redirector.err"/>
</redirector>
</execMyProgram>


Jan
-----Ursprüngliche Nachricht-----
Gesendet: Montag, 29. Mai 2017 12:17
Betreff: Re: macrodef with parameters to pass to java task
Post by Al Le
in my ant script I'd like to define a macro (via macrodef) which
would call the 'java' task as a part of its body/implementation.
Post by Al Le
In the java task call in the macro, I want to just specify the main
class name and the classpath. The parameters (which are usually
specified via nested 'arg' elements) should be as variable as they are
in the original java task.
Post by Al Le
How would I accomplish this?
<macrodef name="execMyProgram">
<element name="programArgs" implicit="true"
description="'arg'
Post by Al Le
entries for the program, use like in the java task"/>
<sequential>
<java classname="my.class.name"
classpathref="my.classpath">
Post by Al Le
<programArgs/>
</java>
</sequential>
</macrodef>
This is the correct way to do it. "implicit=true" means any element you
nest into <execMyProgram> later will get collected as child of your
<programArgs> element and you don't need to use that element name
explicitly.
So instead of
Post by Al Le
<execMyProgram>
<programArgs>
<arg value="arg1"/>
<arg value="arg2"/>
</programArgs>
</executeProcessMonitor>
you only have to use
<execMyProgram>
<arg value="arg1"/>
<arg value="arg2"/>
</executeProcessMonitor>
Stefan
---------------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: user-***@ant.apache.org
For additional commands, e-mail: user-***@ant.apache.org
Al Le
2017-05-29 11:03:01 UTC
Permalink
Yes, it works! Thank you!
Gesendet: Montag, 29. Mai 2017 um 12:16 Uhr
Betreff: Re: macrodef with parameters to pass to java task
Post by Al Le
in my ant script I'd like to define a macro (via macrodef) which would call the 'java' task as a part of its body/implementation.
In the java task call in the macro, I want to just specify the main class name and the classpath. The parameters (which are usually specified via nested 'arg' elements) should be as variable as they are in the original java task.
How would I accomplish this?
<macrodef name="execMyProgram">
<element name="programArgs" implicit="true" description="'arg' entries for the program, use like in the java task"/>
<sequential>
<java classname="my.class.name" classpathref="my.classpath">
<programArgs/>
</java>
</sequential>
</macrodef>
This is the correct way to do it. "implicit=true" means any element you
nest into <execMyProgram> later will get collected as child of your
<programArgs> element and you don't need to use that element name
explicitly.
So instead of
Post by Al Le
<execMyProgram>
<programArgs>
<arg value="arg1"/>
<arg value="arg2"/>
</programArgs>
</executeProcessMonitor>
you only have to use
<execMyProgram>
<arg value="arg1"/>
<arg value="arg2"/>
</executeProcessMonitor>
Stefan
---------------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: user-***@ant.apache.org
For additional commands, e-mail: user-***@ant.apache.org

Loading...