How to fix Ant import which is only allowed as a top-level task?

≯℡__Kan透↙ 提交于 2019-12-12 06:37:19

问题


The code below throws the following error: import only allowed as a top-level task

<target name="packfiles">
        <if>
            <equals arg1="${pack.type}" arg2="impl1" />
            <then>
                <import as="packimpl" file="myImplementation1.xml">
            </then>
            <else>
                 <import as="packimpl" file="myImplementation2.xml">
            </else>
        </if>

        <antcall target="packimpl.build" />

</target>

回答1:


The task documentation explicitly mentions this:

The import task may only be used as a top-level task. This means that it may not be used in a target.

To solve it, simply move the import outside the target.

<project ...>

   ...

   <if>
       <equals arg1="${pack.type}" arg2="impl1" />
       <then>
           <import as="packimpl" file="myImplementation1.xml">
       </then>
       <else>
            <import as="packimpl" file="myImplementation2.xml">
       </else>
   </if>


   <target name="packfiles">        
      <antcall target="packimpl.build" />
   </target>

   ...

</project>



回答2:


<ac:if> <isset property="some_property_is_set" /> <then> <import file="file1.xml" /> </then> </ac:if>

Try the above before you start declaring the targets

"On execution it will select the proper ProjectHelper to parse the imported file, using the same algorithm as the one executed at startup. The selected ProjectHelper instance will then be responsible to actually parse the imported file"

Source: http://ant.apache.org/manual/Tasks/import.html



来源:https://stackoverflow.com/questions/26681784/how-to-fix-ant-import-which-is-only-allowed-as-a-top-level-task

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!