Ant脚本:让<exec>标记转储整个命令行</exec>

时间:2012-04-24 16:57:47

标签: java eclipse ant

我有一个ant构建脚本,其中包含一个相当复杂的<exec>命令,其中包含许多<arg>个标记,我正在尝试进行故障排除。我想知道在构建它之后是否可以查看整个命令行;或者在eclipse调试器中,或者可以将其转储到文件中。

以下是我正在处理的内容:

<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>

这是我得到的错误:

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

3 个答案:

答案 0 :(得分:16)

ant -v通常可以解决这个问题,但你可能会发现你需要输出很多输出。

答案 1 :(得分:10)

一些好的旧回声如何:

<echoxml>
 <exec executable="..." failonerror="true" >
  <arg value=".../>
  <arg value="..."/>
   ...
 </exec>
<echoxml>

用于在激活真实物之前测试你的东西(属性值,属性已解决等等)! 这就是我经常使用的,因为ant -verbose |当我只需要检查特定部分时,调试就是健谈。然后简单地删除或评论echoxml标签 对于echoxml,您需要Ant&gt; = 1.7

答案 2 :(得分:6)

尝试使用log4j ANT listener。它可以配置为在Exec任务输出上为零。

实施例

项目文件

$ 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

运行构建

需要指定侦听器和包含log4j依赖项的目录:

ant -listener org.apache.tools.ant.listener.Log4jListener -lib lib

build.log 文件

中生成以下输出
$ 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