【发布时间】:2017-04-13 19:05:59
【问题描述】:
我需要使用 Ant 构建文件在 Windows 机器中启动作为服务(应用程序)运行的 Tomcat 应用程序。我可以对可用的批处理文件执行相同的操作来启动和关闭。但是,现在我想在没有批处理文件的情况下实现这一点。
注意:现在tomcat作为应用服务运行
【问题讨论】:
我需要使用 Ant 构建文件在 Windows 机器中启动作为服务(应用程序)运行的 Tomcat 应用程序。我可以对可用的批处理文件执行相同的操作来启动和关闭。但是,现在我想在没有批处理文件的情况下实现这一点。
注意:现在tomcat作为应用服务运行
【问题讨论】:
你可以这样做:
首先创建一个名为服务的宏:
<macrodef name="service">
<attribute name="service" />
<attribute name="action" />
<sequential>
<exec executable="cmd.exe">
<arg line="/c net @{action} '@{service}'" />
</exec>
</sequential>
现在创建一个使用服务宏的任务:
<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" />
【讨论】: