【问题标题】:Start and Stop Tomcat service using Ant使用 Ant 启动和停止 Tomcat 服务
【发布时间】:2017-04-13 19:05:59
【问题描述】:

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

注意:现在tomcat作为应用服务运行

【问题讨论】:

    标签: tomcat ant


    【解决方案1】:

    你可以这样做:

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

      <macrodef name="service">
      <attribute name="service" />
      <attribute name="action" />
      <sequential>
          <exec executable="cmd.exe">
              <arg line="/c net @{action} '@{service}'" />
          </exec>
      </sequential>
      

    2. 现在创建一个使用服务宏的任务:

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

    【讨论】:

      猜你喜欢
      • 2016-12-03
      • 1970-01-01
      • 2014-03-12
      • 2012-03-02
      • 1970-01-01
      • 1970-01-01
      • 2019-04-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多