在javaEE项目中,需要将工程部署到远程服务器上,如果部署的频率比较高,手动部署的方式就比较麻烦,可以利用Ant工具实现快捷的部署。这篇博文详细介绍了ant配置的步骤(http://www.cnblogs.com/GloriousOnion/archive/2012/12/18/2822817.html),但是在tomcat7以上不适用,需要修改配置,具体如下:
1.配置tomcat的用户角色
tomcat7中的用户角色有:
manager-gui — Access to the HTML interface.
manager-status — Access to the "Server Status" page only.
manager-script — Access to the tools-friendly plain text interface that is described in this document, and to the "Server Status" page.
manager-jmx — Access to JMX proxy interface and to the "Server Status" page.
我们要用到的是manager-script,在tomcat-users.xml 中进行配置。加入以下代码:
<role rolename="manager-script" />
<user username="用户名"password="密码" roles="manager-script">
2.配置Ant环境
3.编写build.xml文件
<project name="工程名"default="redeploy" 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="/应用的名称"/> < !-- Configure properties to access the Manager application --> <property name="url" value="http://你的域名/manager/text"/> < property name="username" value="步骤1中配置的用户名"/> <property name="password" value="步骤1中配置的密码"/> < !-- 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="findleaks" classname="org.apache.catalina.ant.FindLeaksTask"/> < taskdef name="resources" classname="org.apache.catalina.ant.ResourcesTask"/> < 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 ... --> <delete dir="${build}"/> <mkdir dir="${build}"/> <war destfile="${build}/school.war" webxml="WebRoot/WEB-INF/web.xml"> <classes dir="WebRoot/WEB-INF/classes"> <exclude name="**/*.xml"/> </classes> <lib dir="WebRoot/WEB-INF/lib" /> < fileset dir="WebRoot"> <include name="**/**.*" /> <exclude name="**/*.jar"/> <exclude name="**/*.class"/> < /fileset> </war> < /target> < target name="deploy" description="Install web application" depends="compile"> < deploy url="${url}" username="${username}" password="${password}" path="${path}" war="${build}/school.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> <target name="redeploy" description="Remove and Install web application"> <antcall target="undeploy"/> <antcall target="deploy"/> </target> </project>
最后运行该文件,你的工程就可以部署到远程tomcat上了。
具体的说明可参考官方的文档:
http://tomcat.apache.org/tomcat-7.0-doc/manager-howto.html#Executing_Manager_Commands_With_Ant
Android KSOAP2调用.net webservice
jQuery教程(8)-DOM树操作之使用反向插入方法
android学习笔记(34)使用AlertDialog创建简单对话框
android学习笔记(33)画廊视图(Gallery)的功能和用法
android navidgation drawer 在导航抽屉中如何改变List选中项的...
相关推荐
Ant远程部署tomcat脚本
ant脚本,讲本地代码copy到远程linux服务器的tomcat目录下,并重启tomcat,需要下载jsch.jar包放到本地ant-home的lib目录下
自己整理的在Eclipse下部署远程tomcat的步骤及相关build文件
使用Ant构建web项目 从编译到测试 生成测试报告 打包 邮件发送 远程下载tomcat 部署运行一条龙服务之ant脚本
其实以前在使用eclipse的时候就想在maven下使用插件进行远程部署,无耐,多次试验,都没有成功,IDE换到了idea自己也尝试了下,感觉配置要容易了许多,经过简单的也成功了,现在记录如下。 二、环境配置 在服务器上...
通过这个应用,辅助于Ftp,你可以在远程通过Web部署和撤销应用。Tomcat不仅仅是一个Servlet容器,它也具有传统的Web服务器的功能:处理Html页面。但是与Apache相比,它的处理静态Html的能力就不如Apache。我们可以将...
使用远程shell来进行监控和管理 i. 43.1. 连接远程shell i. 43.1.1. 远程shell证书 ii. 43.2. 扩展远程shell i. 43.2.1. 远程shell命令 ii. 43.2.2. 远程shell插件 v. 44. 度量指标(Metrics) i. 44.1. 系统指标 ...
Servlet/JSP Servlet生命周期及Servlet服务器、Tomcat部署配置、JSP语法、自定义标记、JSTL和EL表达式、JSP 新特性、Java Web 设计模式。 透彻理解Servlet核心原理;熟练掌握Servlet API;透彻理解JSP引擎工作原理;...
一个Java API(远程或本地)将模块部署到这些容器中,无论是单独的服务器,服务器场还是群集。 用来解析/创建/合并J2EE模块的Java API。 ANT任务包装了Java API,用于配置,启动,停止和将应用程序部署到所有受...
1.1.2. 在Tomcat 服务器上运行示例.......................................................................................................................... 15 1.1.3. 运行测试..............................