In Ant, does the order of tasks inside the target be performed?

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 a stop before starting? Or should I make two separate goals and start to depend on a stop?

+4
source share
3 answers

In general, you can rely on Ant to perform tasks in order. <start> not executed until <stop> .

However, given the nature of Tomcat and what it means to β€œstop Tomcat,” what StopTask actually does is something like

  • Connect to the Tomcat disconnect port and tell Tomcat to gracefully close
  • After sending the message, exit

Therefore, you can expect StopTask to complete before Tomcat completes the shutdown process - the task simply tells Tomcat to shut down and not wait for it to close.

You will need a different mechanism in your script to make sure that you are not trying to start the Tomcat instance while another instance on the same port is still in the shutdown phase (for example, sleeping an arbitrary number of seconds).

+5
source

Yes, the order of the tasks matters, and in your case, "stop" with a run before "start". However, "stop tomcat" (the process, not just the task) is not guaranteed before the "start" begins.

You might want to do a β€œstart” and wait for tomcat to start before starting a new instance.

+2
source

Yes, the stop will be started before the start. Of course, creating two separate goals allows you to start and stop with ant, which can be individually useful.

+1
source

Source: https://habr.com/ru/post/1313906/


All Articles