首页 > 系统服务 > 详细

ant调用shell命令(Ubuntu)

时间:2016-05-24 22:37:40      阅读:457      评论:0      收藏:0      [点我收藏+]

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

ant调用shell命令(Ubuntu)

原文:http://www.cnblogs.com/luolizhi/p/5524842.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!