问题
I need to start Tomcat application running as a service (application) in windows machine with an Ant buildfile. I am able to do the same with available batch file to start up and shutdown. But, now I want to make this happen without batch file.
Note: Now tomcat is running as application service
回答1:
You can do it this way:
First Create a macro named service:
<macrodef name="service"> <attribute name="service" /> <attribute name="action" /> <sequential> <exec executable="cmd.exe"> <arg line="/c net @{action} '@{service}'" /> </exec> </sequential>
Now create a task that uses the service macro:
<property name="servicename" value="myWindowsServiceName" /> <target name="start"> <service action="start" service="${servicename}" /> </target> <target name="stop"> <service action="stop" service="${servicename}" /> <exec dir="." executable="cmd.exe"> <arg line ="/c taskkill /f /fi 'services eq ${servicename}' " /> </exec> <sleep seconds="5" /> </target> <target name="restart" depends="stop,start" />
来源:https://stackoverflow.com/questions/32826211/start-and-stop-tomcat-service-using-ant