How can I deploy web app on Tomcat from running app

前端 未结 3 1845
死守一世寂寞
死守一世寂寞 2021-01-06 14:19

I would like to develop updater app. Lets say I\'ve got:
- Running Tomcat
- Running Updater App on the Tomcat
- Running old version of the app on the same Tomcat

3条回答
  •  南笙
    南笙 (楼主)
    2021-01-06 15:00

    Yes. There's a set of tools (well, a .jar) released with Tomcat that's usually used by ant but that can be used by anyone willing to call the code. There are tasks for starting and stopping applications, deploying, undeploying, listing applications and so forth; essentially it's an API that wraps the functionality of the manager servlet.

    One moment while I try to dig up the name or a link for you...

    Here's Apache's information on this stuff: http://tomcat.apache.org/tomcat-5.5-doc/manager-howto.html#Executing Manager Commands With Ant

    ... and here's a user, elsewhere, describing in detail how he uses these tasks: http://raibledesigns.com/wiki/Wiki.jsp?page=TomcatAntTasks

    You may object that you're not ant. That's true, but there's nothing magic about ant, it's just calling code inside the jar. That code can be called from anywhere else that follows the API.

    Here's a tutorial on writing ant tasks: http://ant.apache.org/manual/tutorial-writing-tasks.html

    Not quite the same, but it should give you an idea of how the API works.

    I see no reason why you shouldn't be able to call this API from within a servlet if you want to.

    Alternatively, you could run the manager servlet in your Tomcat and simply access the manager application like a Web service: Use your browser or WireShark to snoop on the traffic between your browser and Tomcat when you deploy an app, and then duplicate that to remote control manager. Me, I think using the tools jar is simpler.

提交回复
热议问题