Antcall:从另一个文件调用嵌套的ant目标

时间:2013-07-12 13:42:58

标签: file ant antcall

我有两个蚂蚁文件:

1)主文件

<include file="otherFile.xml" as="otherFile"/>

<target name="firstTarget">
    <antcall target="otherFile.secondTarget"/>
</target>

2)实用工具文件

<target name="secondTarget">
    <antcall target="thirdTarget"/>
</target>

<target name="thirdTarget">
     <echo message="ok"/> 
</target>

当我调用firstTarget时,它说找不到thirdTarget。 如果我以这种方式更改secondTarget

<target name="secondTarget">
    <antcall target="otherFile.thirdTarget"/>
</target>

然后它的工作原理。但是我不能直接使用secondTarget。因为第二个文件没有使用前缀otherFile

6 个答案:

答案 0 :(得分:2)

您可以尝试:

<ant antfile="otherFile.xml" target="secondTarget"/>

无需包含otherFile。

答案 1 :(得分:1)

在任何直接调用和包含的文件中使用以下模式:

<antcall target="${self}target" />

然后使用以下内容进行antcall:

<script type="text/javascript"> 
// Ajax post 
 $(document).ready(function() { 
 $(".submit").click(function() { 

var message = $("textarea#l_message").val(); 

 jQuery.ajax({ 
 type: "POST", 
 url: "<?php echo base_url(); ?>" + "admin/user_data_submit", 
 dataType: 'json', 
 data: {l_message: message}, 
 success: function(res) { 
 if (res) 
 { 
  // Show Entered Value 
 jQuery("div#msg").show(); 
 jQuery("div#msg").html('Update Successfully!'); 
 window.setTimeout(function() {
    $("#msg").fadeTo(1000, 0).slideUp(1000, function(){
        $(this).remove(); 
  });
}, 5000);
} else {
 } 
} 
 }); 
  return false; 
 }); 
}); 

 </script>

答案 2 :(得分:0)

ANT文档说:

对于每个包含的文件,

,Ant添加一个属性,该属性包含所包含的构建文件的路径。使用此路径,包含的构建文件可以保留资源并能够相对于其位置引用它们。 因此,如果我包含一个名为builddocs的docsbuild.xml文件,我可以将其路径作为ant.file.builddocs,类似于主构建文件的ant.file属性。

您可以利用它来做您想做的事情,即无论是从“包含”上下文还是从顶级上下文调用,都可以使用antcall。你应该做的是将一个属性的值设置为otherFile.context为'otherFile'。如果属性ant.file.otherFile被定义,那么''(即空字符串)如果不是。然后你可以使用属性扩展来调用目标;例如:

<antcall target="${otherFile.context}thirdTarget"/>

没有尝试过,但我认为没有理由不这样做。

答案 3 :(得分:0)

你是否在没有fileName(只是secondTarget)的情况下尝试了它:

<target name="firstTarget">
    <antcall target="secondTarget"/>
</target>

并导入它而不带别名;

<include file="otherFile.xml"/>

有一次,我确实喜欢这个并且有效。

答案 4 :(得分:0)

<import file="otherFile.xml"/>    
<target name="firstTarget">
        <antcall target="secondTarget"/>
</target>

使用导入任务上传文件,它为我工作!!!!

答案 5 :(得分:-1)

您可以对目标位于以下相同文件中进行蚂蚁调用:

<target name="secondTarget">
    <antcall target="thirdTarget" antfile="${ant.file}"/>
</target>