使用Ant启动和停止Tomcat服务 [英] Start and Stop Tomcat service using Ant

查看:137
本文介绍了使用Ant启动和停止Tomcat服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用Ant构建文件在Windows机器中启动作为服务(应用程序)运行的Tomcat应用程序.我可以对可用的批处理文件执行相同的操作来启动和关闭.但是,现在我要在没有批处理文件的情况下实现这一目标.

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.

注意:现在,tomcat正在作为应用程序服务运行

Note: Now tomcat is running as application service

推荐答案

您可以这样做:

  1. 首先创建一个名为service的宏:

  1. 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" />

这篇关于使用Ant启动和停止Tomcat服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆