Start and Stop Tomcat service using Ant

天大地大妈咪最大 提交于 2020-01-11 07:55:07

问题


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:

  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>
    

  2. 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!