I have a ant target that takes a variable number of arguments that are to be passed to an exec task. Using the old mechanism it is trivial:
<exec command="cmd /c ${_full-path-to-exec}" osfamily="windows" failonerror="true">
</exec>
However, use of 'command' is deprecated in favor of nested elements. like this:
<exec executable="cmd" osfamily="windows" failonerror="true">
<arg value="/c"/>
<arg file="${_full-path-to-exec}"/>
<arg value="${_param-one}"/>
<arg value="${_param-two}"/>
<arg value="${_param-three}"/>
</exec>
which makes variable argument lists impossible.
How to solve this problem?
How about this:
<arg line="whatever args you need"/>
Related
I have an ant task, which takes multiple arguments. I would like to pass the arguments loaded from file/property.
I tried the below code, but got error.
<loadfile property="file" srcfile="names.properties"/>
<java classname="com.task.MyTask" fork="true" failonerror="true">
<for param="line" list="${file}">
<arg value="--names"/>
<arg value="${line}"/>
</for>
</java>
Thanks in advance for any help.
<exec dir="${basedir}" executable="cmd.exe">
<arg line="start cmd /c java -jar ${jar.file} "/>
</exec>
In Eclipse this does not work, I would like to open my app.
The reason is io.Console because this I can't execute the app in Eclipse.
cmd appears in two places: In the executable attribute and in the <arg>. It should only appear in the executable attribute.
Further, the /c option of cmd.exe should appear before the start command, not after.
Try the following:
<exec executable="cmd.exe" failonerror="true">
<arg value="/c"/>
<arg value="start"/>
<arg value="java"/>
<arg value="-jar"/>
<arg value="${jar.file}"/>
</exec>
Program works fine when run with eclipse run configurations, but when run with ant, it is unable to parse int from args[0], which I do not understand. Full code is available here https://gist.github.com/4108950/e984a581d5e9de889eaf0c8faf0e57752e825a97
I believe it has something to do with ant,
target name="run" description="run the project">
java dir="${build.dir}" classname="BinarySearchTree" fork="yes">
<arg value="6 in.txt"/>
/java>
/target>
the arg value will be changed via the -D flag, as in ant -Dargs="6 testData1.txt" run.
Any help would be much appreciated, it is very frustrating.
You need to supply the arguments as two different arg values:
<target name="run" description="run the project">
<java dir="${build.dir}" classname="BinarySearchTree" fork="yes">
<arg value="6" />
<arg value="in.txt" />
</java>
</target>
You can also use the line attribute; From the ANT docs:
<arg value="-l -a"/>
is a single command-line argument containing a space character, not separate commands "-> l" and "-a".
<arg line="-l -a"/>
This is a command line with two separate arguments, "-l" and "-a".
Expanding epoch 's answer.
java task supports sysproperty and jvmarg.
For example (from ant java task page)
<java classname="test.Main"
fork="yes" >
<sysproperty key="DEBUG" value="true"/>
<arg value="-h"/>
<jvmarg value="-Xrunhprof:cpu=samples,file=log.txt,depth=3"/> </java>
So you could construct the args from the command line passed to ant.
<target name="run" description="run the project">
<java dir="${build.dir}" classname="BinarySearchTree" fork="yes">
<sysproperty key="testarg" value="${testarg}"
<arg value="${arg1}" />
<arg value="${arg2}" />
</java>
</target>
Now if you call ant with ant -Dtestarg=test1234 -Darg1=6 -Darg2=in.txt, then testarg will be available via property. Others will become normal arguments to the java program.
I have an ant build script with a fairly complex <exec> command with lots of <arg> tags that I'm trying to troubleshoot. I was wondering if it is possible to view the entire command line after ant has constructed it; either in the eclipse debugger or maybe by dumping it to a file.
Here's what I'm dealing with:
<exec executable='"#{sdk}/bin/mxmlc.exe"' failonerror="true" >
<arg line='-load-config "#{sdk}/frameworks/flex-config.xml"'/>
<!-- Flex Build Path -->
<!-- Source path -->
<!-- Main source folder: -->
<arg line='-compiler.source-path "#{project-dir}/src"'/>
<!-- Additional source folders outside of the main source folder: -->
<arg line='-compiler.source-path "#{project-dir}/inc/swf"'/>
<arg line='-compiler.source-path "#{project-dir}/inc/images"'/>
<!-- Output folder: -->
<arg line='-output "#{output}"'/>
<!-- Library path -->
<!-- Build path libraries: -->
<arg line='-compiler.library-path "#{libs}"'/>
<arg line='-compiler.library-path "#{sdk}/frameworks/libs"'/>
<arg line='-compiler.library-path "#{sdk}/frameworks/locale/en_US"'/>
<arg line='-compiler.library-path "${dcradswcs.flex.path}/libs"'/>
<arg line='-compiler.library-path "${dcradswcs.flex.path}/locale"'/>
<arg line='-compiler.library-path "${fiberswcs.flex.path}/libs"'/>
<arg line='-compiler.library-path "${fiberswcs.flex.path}/locale"'/>
<arg line='-compiler.library-path "${flexunitframework.flex.path}/flexunitframework/libs/version4libs/Common"'/>
<arg line='-compiler.library-path "${flexunitframework.flex.path}/flexunitframework/libs/version4libs/FlexProject"'/>
<arg line='-compiler.library-path "${flexunitframework.flex.path}/flexunitframework/locale/version4locale"'/>
<arg line='-compiler.library-path "${flexunitframework.flex.path}/flexunitframework/libs"'/>
<!-- <arg line='-compiler.library-path "C:/rms-it-apps/adobe/fb4/plugins/com.adobe.flexbuilder.dcrad_4.0.1.277662/dcradSwcs/4.0/libs"'/>
<arg line='-compiler.library-path "C:/rms-it-apps/adobe/fb4/plugins/com.adobe.flexbuilder.dcrad_4.0.1.277662/dcradSwcs/4.0/locale"'/>
<arg line='-compiler.library-path "C:/rms-it-apps/adobe/fb4/plugins/com.adobe.flexbuilder.dcrad_4.0.1.277662/fiberSwcs/4.0/libs"'/>
<arg line='-compiler.library-path "C:/rms-it-apps/adobe/fb4/plugins/com.adobe.flexbuilder.dcrad_4.0.1.277662/fiberSwcs/4.0/locale"'/>
<arg line='-compiler.library-path "C:/rms-it-apps/adobe/fb4/plugins/com.adobe.flexbuilder.flexunit_4.0.1.277662/flexunitframework/libs/version4libs/Common"'/>
<arg line='-compiler.library-path "C:/rms-it-apps/adobe/fb4/plugins/com.adobe.flexbuilder.flexunit_4.0.1.277662/flexunitframework/libs/version4libs/FlexProject"'/>
<arg line='-compiler.library-path "C:/rms-it-apps/adobe/fb4/plugins/com.adobe.flexbuilder.flexunit_4.0.1.277662/flexunitframework/locale/version4locale"'/>
<arg line='-compiler.library-path "C:/rms-it-apps/adobe/fb4/plugins/com.adobe.flexbuilder.flexunit_4.0.1.277662/flexunitframework/libs"'/> -->
<!-- Runtime shared libraries. Order matters. -->
<!-- Load framework libraries first -->
<arg line='-runtime-shared-library-path="#{sdk}/frameworks/libs/textLayout.swc","textLayout_1.1.0.604.swz",,"textLayout_1.1.0.604.swf"'/>
<arg line='-runtime-shared-library-path="#{sdk}/frameworks/libs/osmf.swc","osmf_flex.4.0.0.13495.swz",,"osmf_flex.4.0.0.13495.swf"'/>
<arg line='-runtime-shared-library-path="#{sdk}/frameworks/libs/framework.swc","framework_4.1.0.16076.swz",,"framework_4.1.0.16076.swf"'/>
<arg line='-runtime-shared-library-path="#{sdk}/frameworks/libs/spark.swc","spark_4.1.0.16076.swz",,"spark_4.1.0.16076.swf"'/>
<arg line='-runtime-shared-library-path="#{sdk}/frameworks/libs/sparkskins.swc","sparkskins_4.1.0.16076.swz",,"sparkskins_4.1.0.16076.swf"'/>
<arg line='-runtime-shared-library-path="#{sdk}/frameworks/libs/rpc.swc","rpc_4.1.0.16076.swz",,"rpc_4.1.0.16076.swf"'/>
<arg line='-runtime-shared-library-path="#{sdk}/frameworks/libs/datavisualization.swc","datavisualization_4.1.0.16076.swz",,"datavisualization_4.1.0.16076.swf"'/>
<!-- Load after framework libraries -->
<!-- Note: do not put spaces between comma delimited values -->
<arg line='${rsl.applicationSettings}'/>
<arg line='${rsl.authorization}'/>
<arg line='${rsl.autofill}'/>
<arg line='${rsl.customComponents}'/>
<arg line='${rsl.navigation}'/>
<arg line='${rsl.lookup}'/>
<!-- Libraries needed for QTP -->
<arg line="${qtp.arg1}"/>
<arg line="${qtp.arg2}"/>
<arg line="${qtp.arg3}"/>
<arg line="${qtp.arg4}"/>
<arg line="${qtp.arg5}"/>
<arg line="-verify-digests=false"/>
<!-- Flex Compiler -->
<!-- Compiler options -->
<arg line="-compiler.accessible=true"/>
<arg line="-compiler.strict=true"/>
<arg line="-warnings=true" />
<!-- Additional compiler arguments: -->
<arg line='-theme=#{sdk}/frameworks/themes/Halo/halo.swc -services "#{services-config}" -locale en_US'/>
<!-- Flex Server -->
<!-- Server location -->
<!-- Context root: -->
<arg line="-compiler.context-root=#{context-root}"/>
<!-- Miscellaneous -->
<arg line="-compiler.incremental=true"/>
<arg line="-compiler.keep-generated-actionscript=false"/>
<arg line="-compiler.verbose-stacktraces=true"/>
<arg line="-show-unused-type-selector-warnings=false"/>
<arg line="-optimize=true" />
<arg line="-debug=#{debug}" />
<arg line='"#{mxml}"'/>
</exec>
This is the error I'm getting:
BUILD FAILED
C:\dev\workspace\rmsitepi2\build.raytheon.suite.tomcat.xml:50: The following error occurred while executing this line:
C:\dev\workspace\rmsitepi2\build.raytheon.flex.xml:33: The following error occurred while executing this line:
C:\dev\workspace\rmsitepi2\build.raytheon.flex.xml:159: exec returned: 1
ant -v usually does the trick but you may find you have a lot of output to look through.
What about some good old echoing via:
<echoxml>
<exec executable="..." failonerror="true" >
<arg value="..."/>
<arg value="..."/>
...
</exec>
</echoxml>
for testing your stuff (attribute values, properties resolved .. etc.) before activating the real thing !?
That's what I use frequently, because ant -verbose | debug is too chatty when I need to check only specific parts. Afterwards simply delete or comment the echoxml tags.
For echoxml you need Ant >= 1.7
Try using the log4j ANT listener. It can be configured to zero in on the Exec task output.
Example
Project files
$ tree
.
|-- build.xml
`-- lib
|-- log4j-1.2.16.jar
`-- log4j.properties
1 directory, 3 files
build.xml
<project name="name" default="run">
<target name="run">
<exec executable="echo">
<arg line="hello world"/>
</exec>
</target>
</project>
log4j.properties
log4j.rootLogger=ERROR, LogFile
log4j.logger.org.apache.tools.ant.taskdefs.ExecTask=DEBUG
log4j.appender.LogFile=org.apache.log4j.FileAppender
log4j.appender.LogFile.layout=org.apache.log4j.PatternLayout
log4j.appender.LogFile.layout.ConversionPattern=[%6r] %8c{1} : %m%n
log4j.appender.LogFile.file=build.log
Running the build
Need to specify the listener and the directory containing the log4j dependencies:
ant -listener org.apache.tools.ant.listener.Log4jListener -lib lib
Producing the following output in the build.log file
$ cat build.log
[ 0] ExecTask : Current OS is Linux
[ 14] ExecTask : Executing 'echo' with arguments:
'hello'
'world'
The ' characters around the executable and arguments are
not part of the command.
[ 20] ExecTask : hello world
I am trying to add some tag information in my ant script using the following target but I get an error (Result=-1) and hg tells me it does not recognise the command:
<target name="-post-init">
<exec outputproperty="hg.tag" executable="hg">
<arg value="parents --template {latesttag}+{latesttagdistance}" />
</exec>
</target>
If I only include value="parents" it works fine.
If I run the command line hg parents --template {latesttag}+{latesttagdistance} it works fine too.
Any ideas on what is wrong in my syntax?
Just tried this and it works fine:
<exec outputproperty="hg.tag" executable="hg">
<arg value="parents" />
<arg value="--template" />
<arg value="{latesttag}+{latesttagdistance}" />
</exec>
I needed to split the arguments.