今天无意中发现tomcat5.5的管理功能已经非常强大了,只要你配置好了tomcat-user.xml.

主要是增加一个具有系统管理权限的用户,比如增加一个用户名和密码都是suxiaoyong的用户,只需要在在最后一行增加

代码
<user username="suxiaoyong" password="suxiaoyong" roles="admin,manager"/>


其他的用户都可以删掉了

然后,我们可以进入http://localhost:8080/manager/status 来查看服务器的各种状态.

也可以通过url来直接对应用进行监控

命令格式
代码
http://{ host }:{ port }/manager/{ command }?{ parameters }


部署一个应用

代码
http://localhost:8080/manager/deploy?path=/foo

http://localhost:8080/manager/deploy?path=/foo

http://localhost:8080/man......o&war=file:/path/to/foo

http://localhost:8080/manager/deploy?war=foo

http://localhost:8080/man......ath=/bartoo&war=bar.war


列出已经部署的应用

代码
http://localhost:8080/manager/list


重新加载一个应用


比如你更新了class或者lib的话,需要重新加载系统

代码
http://localhost:8080/manager/reload?path=/examples


查看jvm和系统信息

代码
http://localhost:8080/manager/serverinfo


查看可用的安全角色

代码
http://localhost:8080/manager/roles


查看某个应用默认的session超时时间和当前活跃的session数

代码
http://localhost:8080/manager/sessions?path=/examples


启动一个应用

比如有时候重新启动数据库后可能需要重新启动应用

代码
http://localhost:8080/manager/start?path=/examples


关闭一个应用

关闭后,任何发往该应用的请求都将转向404错误的页面

代码
http://localhost:8080/manager/stop?path=/examples

 
undeploy

慎用,将删除应用的目录及其war文件

ant脚本,更多的详见tomcat5.5的文档

代码
<project name="My Application" default="compile" basedir=".">

 <!-- Configure the directory into which the web application is built -->
 <property name="build"    value="${ basedir }/build"/>

 <!-- Configure the context path for this application -->
 <property name="path"     value="/myapp"/>

 <!-- Configure properties to access the Manager application -->
 <property name="url"      value="http://localhost:8080/manager"/>
 <property name="username" value="myusername"/>
 <property name="password" value="mypassword"/>

 <!-- Configure the custom Ant tasks for the Manager application -->
 <taskdef name="deploy"    classname="org.apache.catalina.ant.DeployTask"/>
 <taskdef name="list"      classname="org.apache.catalina.ant.ListTask"/>
 <taskdef name="reload"    classname="org.apache.catalina.ant.ReloadTask"/>
 <taskdef name="resources" classname="org.apache.catalina.ant.ResourcesTask"/>
 <taskdef name="roles"     classname="org.apache.catalina.ant.RolesTask"/>
 <taskdef name="start"     classname="org.apache.catalina.ant.StartTask"/>
 <taskdef name="stop"      classname="org.apache.catalina.ant.StopTask"/>
 <taskdef name="undeploy"  classname="org.apache.catalina.ant.UndeployTask"/>

 <!-- Executable Targets -->
 <target name="compile" description="Compile web application">
   <!-- ... construct web application in ${ build } subdirectory, and
           generated a ${ path }.war ... -->
 </target>

 <target name="deploy" description="Install web application"
         depends="compile">
   <deploy url="${ url }" username="${ username }" password="${ password }"
           path="${ path }" war="${ build }${ path }.war"/>
 </target>

 <target name="reload" description="Reload web application"
         depends="compile">
   <reload  url="${ url }" username="${ username }" password="${ password }"
           path="${ path }"/>
 </target>

 <target name="undeploy" description="Remove web application">
   <undeploy url="${ url }" username="${ username }" password="${ password }"
           path="${ path }"/>
 </target>

</project>