如何使用 Ant 连接到远程服务器并启动/停止在该特定服务器上运行的 Tomcat?

如何使用 Ant 连接到远程服务器并启动/停止在该特定服务器上运行的 Tomcat?

问题描述:

1: connect to a remote server maybe via host: ip , port: 8181
2: stop Tomcat that's running on that server 
3: deploy a .war file 
4: restart tomcat 

我相信 Tomcat 文档监控和管理 Tomcat 下提供了一些关于如何停止给定应用程序的信息,但不是完全服务器:

I believe Tomcat Documentation under Monitoring and Managing Tomcat offers some information on how to stop a given application, but not the server entirely:

<jmx:invoke
    name="Catalina:type=Manager,path=/servlets-examples,host=localhost" 
    operation="stop"/>

如果您可以通过 ssh 访问服务器,那么您可能需要考虑 JSch 库,您可以结合使用它使用 SSHExec Ant Task 来启动和停止您的服务器:

If you have ssh access to the server, then you might like to consider the JSch library which you can use in combination with SSHExec Ant Task to start and stop your server:

<sshexec host="somehost"
    username="dude"
    password="yo"
    command="/etc/init.d/tomcat restart"/>