Java 使用批处理文件重新启动远程tomcat以停止手动干预以重新启动?

Java 使用批处理文件重新启动远程tomcat以停止手动干预以重新启动?,java,windows,tomcat,batch-file,cmd,Java,Windows,Tomcat,Batch File,Cmd,我想使用批处理文件重新启动远程tomcat实例。可能吗 流量: 可能吗?如果是这样,你能给我一些见解来实现这一点吗 谢谢 当然有可能。 在我的头顶上: 您可以使用可以在tomcat bin目录中找到的脚本(startup,shutdown,catalina)来控制tomcat。文件扩展名取决于平台(.bat适用于windows,.sh适用于Unix 要远程运行这些脚本,请使用ssh或telnet连接 您还可以使用服务管理器控制tomcat。工具取决于您的平台 您可以远程部署、启动、停止和重新启动

我想使用批处理文件重新启动远程tomcat实例。可能吗

流量:

可能吗?如果是这样,你能给我一些见解来实现这一点吗

谢谢

当然有可能。 在我的头顶上:

  • 您可以使用可以在tomcat bin目录中找到的脚本(
    startup
    shutdown
    catalina
    )来控制tomcat。文件扩展名取决于平台(
    .bat
    适用于windows,
    .sh
    适用于Unix
  • 要远程运行这些脚本,请使用ssh或telnet连接
  • 您还可以使用服务管理器控制tomcat。工具取决于您的平台

  • 您可以远程部署、启动、停止和重新启动tomcat。为此,您必须执行以下步骤:

  • 要控制tomcat,可以编写ant构建脚本
  • 编写批处理脚本并调用ant脚本以执行所需的目标。例如停止tomcat
  • 完成你想要的任务
  • 在ant脚本中执行目标以再次启动tomcat
  • 如何远程操作tomcat您可以使用以下链接:


    我编写了一个ant构建脚本,它将重新启动tomcat并清除tomcat缓存。只需将xml文件放入tomcat/bin。用于等待服务器停止的代码似乎并不适用于所有系统,因此我只添加了一个只需等待3分钟的目标

    {code}

    
    

    {code}

    AlexR,你能给我一些启动和停止tomcat的批处理脚本吗?谢谢!@user3269829,你可以在
    tomcat_HOME/bin
    Rahul下找到所有脚本,非常感谢你的建议。你有任何关于这个的示例吗?你想要哪种类型的示例?从批处理文件调用Ant脚本..谢谢!
    Stop tomcat
    
    execute some sql script
    
    start tomcat
    
    <property name="startServer.dir" value="." />
    <property name="startServer.cmd.unix" value="startup.sh"/>
    <property name="startServer.cmd.windows" value="startup.bat"/>
    <property name="stopServer.cmd.unix" value="shutdown.sh"/>
    <property name="stopServer.cmd.windows" value="shutdown.bat"/>
    <property name="maven.port" value="8080"/>
    <property name="deployed.cache" value="../work"/>
    
    
    <!-- stop web server targets -->
    <target name="stop" depends="" description="stop app server which is configured on this system">
        <echo message="Attempting to stop app server ${startServer.dir}"/>
        <echo message="${stopServer.cmd.unix} / ${stopServer.cmd.windows}"/>
        <exec dir="${startServer.dir}" osfamily="unix" executable="sh" timeout="18000">
            <arg line="${stopServer.cmd.unix}"/>
        </exec>
        <exec dir="${startServer.dir}" osfamily="windows" executable="cmd" timeout="18000">
            <arg line="/c ${stopServer.cmd.windows}"/>
        </exec>
        <echo message="waiting for server to stop"/>
        <waitfor maxwait="5" maxwaitunit="minute" checkevery="500">
            <not>
                <http url="http://localhost:${maven.port}"/>
            </not>
        </waitfor>
    </target>
    
    <target name="pause">
        <echo message="Pausing for 3 minutes to make sure server is stopped" />
        <sleep minutes="3"/>
    </target>
    
    <!-- start web server targets -->
    <target name="start" description="start app server which is configured on this system">
        <echo message="Attempting to start app server server ${startServer.dir}"/>
        <echo message="${startServer.cmd.unix} / ${startServer.cmd.windows}"/>
        <exec dir="${startServer.dir}" osfamily="unix" executable="sh" spawn="true">
            <arg line="${startServer.cmd.unix}"/>
        </exec>
        <exec dir="${startServer.dir}" osfamily="windows" executable="cmd" spawn="true">
            <arg line="/c ${startServer.cmd.windows}"/>
        </exec>
    </target>
    
    <target name="cleanTomcat" description="Remove tomcat cashe">
        <delete dir="${deployed.cache}" verbose="true"/>
    </target>
    
    <target name="restart" depends="stop,pause,cleanTomcat,start"/>