Use ant for remote tomcat deployment and anttomcat deployment
In the javaEE project, you need to deploy the project to a remote server. If the deployment frequency is high, manual deployment is troublesome. You can use the Ant tool for Fast deployment. This blog post details the ant configuration steps (http://www.cnblogs.com/GloriousOnion/archive/2012/12/18/2822817.html), but not applicable in tomcat7 or above, you need to modify the configuration as follows:
1. Configure the tomcat User Role
The user roles in Tomcat 7 include:
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 isdescribed in this document, and to the "Server Status" page.
Manager-jmx-Access to JMX proxy interface and to the "ServerStatus" page.
We need to use manager-script for configuration in the tomcat-users.xml. Add the following code:
<Role rolename = "manager-script"/>
<User username = "username" password = "password" roles = "manager-script">
2. Configure the Ant Environment
Previously in 6.0, we will add catalina-ant.jar package in classpath, the specific operation is: window --> preferences, left: ant --> runtime, add external jars under the global entries in the classpath label on the right, the path points to tomcat_home/lib/catalina-ant.jar, just this one, but now 7.0 has to add a few more: lib/catalina-ant.jar, lib/tomcat-coyote.jar, lib/tomcat-util.jar, bin/tomcat-juli.jar
3. Compile the build. xml file
<Project name = "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 = "/Application name"/>
<! -- Configure properties to access the Manager application -->
<Property name = "url" value = "http: // your domain name/manager/text"/>
<Property name = "username" value = "username configured in step 1"/>
<Property name = "password" value = "password configured in step 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 webapplication">
<! --... Construct web application in $ {build} subdirectory, and
Generated a $ {path}. war... -->
<Deletedir = "$ {build}"/>
<Mkdir dir = "$ {build}"/>
<Wardestfile = "$ {build}/school. war" webxml = "WebRoot/WEB-INF/web. xml">
<Classesdir = "WebRoot/WEB-INF/classes">
<Excludename = "**/*. xml"/>
</Classes>
<Libdir = "WebRoot/WEB-INF/lib"/>
<Fileset dir = "WebRoot">
<Includename = "**/**. *"/>
<Excludename = "**/*. jar"/>
<Excludename = "**/*. class"/>
</Fileset>
</War>
</Target>
<Target name = "deploy" description = "Install webapplication" depends = "compile">
<Deploy url = "$ {url}" username = "$ {username}" password = "$ {password}" path = "$ {path}" war = "$ {build }/school. war "/>
</Target>
<Target name = "reload" description = "Reload webapplication" depends = "compile">
<Reload url = "$ {url}" username = "$ {username}" password = "$ {password}" path = "$ {path}"/>
</Target>
<Target name = "undeploy" description = "Remove webapplication">
<Undeploy url = "$ {url}" username = "$ {username}" password = "$ {password}" path = "$ {path}"/>
</Target>
<Targetname = "redeploy" description = "Remove and Install webapplication">
<Antcalltarget = "undeploy"/>
<Antcalltarget = "deploy"/>
</Target>
</Project>
Finally, run the file to deploy your project to remote tomcat.
For details, refer to the official documents:
Http://tomcat.apache.org/tomcat-7.0-doc/manager-howto.html#Executing_Manager_Commands_With_Ant