ant調用shell命令(Ubuntu)


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

<?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/4231496

 

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

        <target name="mk" >

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

                 </exec>
        </target>
</project>

 

而我們的makefile文件簡單如下:

 

targets:
                @echo "hello make!"
                pwd
                du


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

 

按照build.xml文件,ant將會執行make命令。

 

結果如下:

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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM