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语句没有问题。

原文地址:https://www.cnblogs.com/luolizhi/p/5524842.html