代码之家  ›  专栏  ›  技术社区  ›  Matthew

In Ant, does the order of tasks inside a target matter?

  •  4
  • Matthew  · 技术社区  · 16 年前

    I want to make a target to restart tomcat6. Right now, I have something like this:

    <taskdef name="stop" classname="org.apache.catalina.ant.StopTask" />
    <taskdef name="start" classname="org.apache.catalina.ant.StartTask" />
    
    ...
    
    <target name="restart" depends="deploy" description="Restart Tomcat" >
        <stop url="${manager}" username="${username}" password="${password}" path="${path}" />
        <start url="${manager}" username="${username}" password="${password}" path="${path}" />
    </target>
    

    Can I rely on stop running before start? Or should I make two separate targets, and have 'start' depend on 'stop'?

    3 回复  |  直到 16 年前
        1
  •  5
  •   matt b    16 年前

    一般来说,您可以依赖Ant按顺序执行任务。这个 <start> is not executed until <stop> 完成。

    然而,考虑到Tomcat的性质以及“阻止Tomcat”的含义,什么是 StopTask 实际上是这样的

    1. 连接到Tomcat的关机端口,告诉Tomcat正常关机
    2. 发送消息后,退出

    因此, 停止任务 可以预期完成 之前 Tomcat has completed it's shutdown process - the task merely tells Tomcat to shut down, it does not wait for it to shut down.

    You'll need some other mechanism in your script to make sure that you don't try to start a Tomcat instance while another instance on the same port is still in the midst of shutting down (such as sleeping an arbitrary number of seconds).

        2
  •  2
  •   jprusakova    16 年前

    Yes, order of tasks matters, and in your case 'stop' with run before 'start'. However, 'stop tomcat' (the process, not just the task) is not guaranteed to complete before 'start' will get kicked off.

    You may want to make 'start' check and wait until tomcat is not running before starting a new instance.

        3
  •  1
  •   Rob Di Marco    16 年前

    Yes, stop will run before start. Of course, making two separate targets allows you to start and stop from ant, which may be individually useful.