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語句沒有問題。

相關文章
相關標籤/搜索