{"id":210,"date":"2013-07-28T15:10:09","date_gmt":"2013-07-28T15:10:09","guid":{"rendered":"http:\/\/shirishranjit.com\/blog1\/?page_id=210"},"modified":"2013-07-28T15:17:01","modified_gmt":"2013-07-28T15:17:01","slug":"how-to-integrate-ant-with-tomcat","status":"publish","type":"page","link":"https:\/\/shirishranjit.com\/blog1\/technical-posts\/how-to-integrate-ant-with-tomcat","title":{"rendered":"How to integrate Ant with Tomcat"},"content":{"rendered":"<h1>How to integrate Ant with Tomcat<\/h1>\n<p><b>Objective<\/b>:\u00a0 Use Ant script to build and deploy application into an Apache Tomcat container.<\/p>\n<p><b>Solution<\/b>:\u00a0 Apache provides ant \u201ctaskdef\u201d for most of tomcat management features such as start, stop, deploy, undeply, and redeploy.<\/p>\n<p>There are few pre-requisites or dependencies before those ant task can be used on a tomcat server. Following are pre-requisites:<\/p>\n<p>&nbsp;<\/p>\n<ol>\n<li>Must have catalina-ant.jar file in the library path for the tomcat taskdefs. This is part of Tomcat deployment. This jar must match the version of the tomcat that you are targeting to deploy.<\/li>\n<li>The tomcat URL must be either\u00a0<a href=\"http:\/\/localhost:8080\/manager\">http:\/\/localhost:8080\/manager<\/a>\u00a0or\u00a0<a href=\"http:\/\/localhost:8080\/manager\">http:\/\/localhost:8080\/manager\/text<\/a>. The new version uses \/text while the older version does not require it.<\/li>\n<li>Add roles and a user in tomcat tomcat-users.xml file. Add following roles to the user<\/li>\n<\/ol>\n<ul>\n<li><b><\/b>manager-gui \u2014 Access to the HTML interface.<\/li>\n<li><b><\/b>manager-status \u2014 Access to the &#8220;Server Status&#8221; page only.<\/li>\n<li><b><\/b>manager-script \u2014 Access to the tools-friendly plain text interface that is described in this document, and to the &#8220;Server Status&#8221; page.<\/li>\n<\/ul>\n<p>Make sure that you can login in the tomcat admin page with the user.<\/p>\n<ol>\n<li>Make sure that your paths are correct for war file for library.<\/li>\n<li>This will work for local and remote deployment. For remote, you need to change the URL.<\/li>\n<\/ol>\n<p><code><\/p>\n<p>&lt;!--\u00a0\u00a0 tomcat stuff\u00a0\u00a0\u00a0 --&gt;<\/p>\n<p>&lt;!-- Configure properties to access the Manager applicati --&gt;<\/p>\n<p>&lt;property name=\"url\" value=\"<a href=\"http:\/\/localhost:8080\/manager\">http:\/\/localhost:8080\/manager<\/a>\" \/&gt;<\/p>\n<p>&lt;property name=\"username\" value=\"admin\" \/&gt;<\/p>\n<p>&lt;property name=\"password\" value=\"admin\" \/&gt;<\/p>\n<p>&lt;property name=\"TOMCAT_HOME\" value=\"\/tomcat\" \/&gt;<\/p>\n<p>&nbsp;<\/p>\n<p>&lt;!-- Configure the custom Ant tasks for the Manager application --&gt;<\/p>\n<p>&lt;taskdef name=\"deploy\" classname=\"org.apache.catalina.ant.DeployTask\" classpathref=\"compile.classpath\" \/&gt;<\/p>\n<p>&lt;taskdef name=\"list\" classname=\"org.apache.catalina.ant.ListTask\" classpathref=\"compile.classpath\" \/&gt;<\/p>\n<p>&lt;taskdef name=\"reload\" classname=\"org.apache.catalina.ant.ReloadTask\" classpathref=\"compile.classpath\" \/&gt;<\/p>\n<p>&lt;!-- taskdef name=\"findleaks\" classname=\"org.apache.catalina.ant.FindLeaksTask\" classpathref=\"compile.classpath\" \/--&gt;<\/p>\n<p>&lt;taskdef name=\"resources\" classname=\"org.apache.catalina.ant.ResourcesTask\" classpathref=\"compile.classpath\" \/&gt;<\/p>\n<p>&lt;taskdef name=\"start\" classname=\"org.apache.catalina.ant.StartTask\" classpathref=\"compile.classpath\" \/&gt;<\/p>\n<p>&lt;taskdef name=\"stop\" classname=\"org.apache.catalina.ant.StopTask\" classpathref=\"compile.classpath\" \/&gt;<\/p>\n<p>&lt;taskdef name=\"undeploy\" classname=\"org.apache.catalina.ant.UndeployTask\" classpathref=\"compile.classpath\" \/&gt;<\/p>\n<p>&lt;taskdef name=\"remove\" classname=\"org.apache.catalina.ant.RemoveTask\" classpathref=\"compile.classpath\" \/&gt;<\/p>\n<p>&nbsp;<\/p>\n<p>&lt;target name=\"deploy\" description=\"Install web application\" depends=\"makeWar\"&gt;<\/p>\n<p>&lt;deploy url=\"${url}\" username=\"${username}\" password=\"${password}\" path=\"\/${war.name}\" war=\"file:${dist.dir}\/${war.name}.war\" \/&gt;<\/p>\n<p>&lt;\/target&gt;<\/p>\n<p>&nbsp;<\/p>\n<p>&lt;target name=\"reload\" description=\"Reload web application\" depends=\"compile\"&gt;<\/p>\n<p>&lt;reload url=\"${url}\" username=\"${username}\" password=\"${password}\" path=\"\/${war.name}\" \/&gt;<\/p>\n<p>&lt;\/target&gt;<\/p>\n<p>&nbsp;<\/p>\n<p>&lt;target name=\"undeploy\" description=\"Remove web application\"&gt;<\/p>\n<p>&lt;undeploy url=\"${url}\" username=\"${username}\" password=\"${password}\" path=\"\/${war.name}\" \/&gt;<\/p>\n<p>&lt;\/target&gt;<\/p>\n<p>&nbsp;<\/p>\n<p>&lt;target name=\"start\"&gt;<\/p>\n<p>&lt;sshexec host=\"${host}\" username=\"${username}\" password=\"${password}\" command=\". \/etc\/profile; ${tomcatHome}\/bin\/catalina.sh start\" trust=\"true\" \/&gt;<\/p>\n<p>&lt;\/target&gt;<\/p>\n<p>&nbsp;<\/p>\n<p>&lt;target name=\"stop\"&gt;<\/p>\n<p>&lt;sshexec host=\"${host}\" username=\"${username}\" password=\"${password}\" command=\". \/etc\/profile; ${tomcatHome}\/bin\/catalina.sh stop\" trust=\"true\" \/&gt;<\/p>\n<p>&lt;\/target&gt;<\/p>\n<p>&nbsp;<\/p>\n<p>&lt;target name=\"remove\" description=\"Remove web application\"&gt;<\/p>\n<p>&lt;remove url=\"${url}\" username=\"${username}\" password=\"${password}\" path=\"${{war.name}\" \/&gt;<\/p>\n<p>&lt;\/target&gt;<\/p>\n<p>&nbsp;<\/p>\n<p>&lt;target name=\"tomcat-start\"&gt;<\/p>\n<p>&lt;java jar=\"${TOMCAT_HOME}\/bin\/bootstrap.jar\" fork=\"true\"&gt;<\/p>\n<p>&lt;jvmarg value=\"-Dcatalina.home=${TOMCAT_HOME}\" \/&gt;<\/p>\n<p>&lt;\/java&gt;<\/p>\n<p>&lt;\/target&gt;<\/p>\n<p>&nbsp;<\/p>\n<p>&lt;target name=\"tomcat-stop\"&gt;<\/p>\n<p>&lt;java jar=\"${TOMCAT_HOME}\/bin\/bootstrap.jar\" fork=\"true\"&gt;<\/p>\n<p>&lt;jvmarg value=\"-Dcatalina.home=${TOMCAT_HOME}\" \/&gt;<\/p>\n<p>&lt;arg line=\"stop\" \/&gt;<\/p>\n<p>&lt;\/java&gt;<\/p>\n<p>&lt;\/target&gt;<\/p>\n<p><\/code><\/p>\n<div class=\"twttr_buttons\"><div class=\"twttr_twitter\">\n\t\t\t\t\t<a href=\"http:\/\/twitter.com\/share?text=How+to+integrate+Ant+with+Tomcat\" class=\"twitter-share-button\" data-via=\"\" data-hashtags=\"\"  data-size=\"default\" data-url=\"https:\/\/shirishranjit.com\/blog1\/technical-posts\/how-to-integrate-ant-with-tomcat\"  data-related=\"\" target=\"_blank\">Tweet<\/a>\n\t\t\t\t<\/div><div class=\"twttr_followme\">\n\t\t\t\t\t\t<a href=\"https:\/\/twitter.com\/shiranjit\" class=\"twitter-follow-button\" data-size=\"default\"  data-show-screen-name=\"false\"  target=\"_blank\">Follow me<\/a>\n\t\t\t\t\t<\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>How to integrate Ant with Tomcat Objective:\u00a0 Use Ant script to build and deploy application into an Apache Tomcat container. Solution:\u00a0 Apache provides ant \u201ctaskdef\u201d for most of tomcat management features such as start, stop, deploy, undeply, and redeploy. There &hellip; <a href=\"https:\/\/shirishranjit.com\/blog1\/technical-posts\/how-to-integrate-ant-with-tomcat\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":198,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-210","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/shirishranjit.com\/blog1\/wp-json\/wp\/v2\/pages\/210"}],"collection":[{"href":"https:\/\/shirishranjit.com\/blog1\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/shirishranjit.com\/blog1\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/shirishranjit.com\/blog1\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/shirishranjit.com\/blog1\/wp-json\/wp\/v2\/comments?post=210"}],"version-history":[{"count":8,"href":"https:\/\/shirishranjit.com\/blog1\/wp-json\/wp\/v2\/pages\/210\/revisions"}],"predecessor-version":[{"id":223,"href":"https:\/\/shirishranjit.com\/blog1\/wp-json\/wp\/v2\/pages\/210\/revisions\/223"}],"up":[{"embeddable":true,"href":"https:\/\/shirishranjit.com\/blog1\/wp-json\/wp\/v2\/pages\/198"}],"wp:attachment":[{"href":"https:\/\/shirishranjit.com\/blog1\/wp-json\/wp\/v2\/media?parent=210"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}