ant调用shell命令(Ubuntu)

  ant中调用Makefile,使用shell中的make命令shell

<?xml version="1.0" encoding="utf-8" ?>  
<project name="dy_cike_init" basedir=".">  
    <target name="hait_cpr" description="">  
        <exec executable="/bin/sh">  
            <arg line="-c make -f /home/test/ant/Makefile"/>  
        </exec>  
    </target>  
</project>  
使用exec

    <target name="copy_lib" description="Copy library files from  project1 to project2">
        <exec executable="cmd.exe">
            <arg line="/c &quot;cd ../project1 &amp;&amp; ant copy_to_project2_lib &quot; "/>
    </exec>
    </target>

 

翻译为命令行就是:cmd.exe /c "cd ../project && ant copy_to_project2_lib"  

意思是直接调用系统控制台,先执行cd命令,再执行ant脚本指定任务,/c 表示执行后续 String 指定的命令,而后中止。

http://blog.csdn.net/samlei/article/details/4231496ui

 

<project name="maketest" default="mk">spa

        <target name="mk" >.net

                <exec dir="/ci/opt/cruisecontrol-bin-2.7.3/projects/maketest" executable="make" os="Linux"  failonerror="true">命令行

                 </exec>
        </target>
</project>翻译

 

而咱们的makefile文件简单以下:code

 

targets:
                @echo "hello make!"
                pwd
                duxml


                @echo "test is ok!">>/ci/opt/cruisecontrol-bin-2.7.3/projects/maketest/test.txtblog

 

按照build.xml文件,ant将会执行make命令。ip

 

结果以下:

[root@localhost maketest]# ant
Buildfile: build.xml

mk:
     [exec] hello make!
     [exec] pwd
     [exec] /ci/opt/cruisecontrol-bin-2.7.3/projects/maketest
     [exec] du
     [exec] 16  .

BUILD SUCCESSFUL
Total time: 1 second
[root@localhost maketest]#

 

咱们能够看到ant已经成功执行,并输出了makefile的结果。这里提醒你们的是,ant在执行过程当中对语法错误的检测是至关宽松的,因此咱们看到ant “build successful”的语句并不必定说明ant语句没有问题。

相关文章
相关标签/搜索