{"id":649,"date":"2004-12-13T07:20:29","date_gmt":"2004-12-13T11:20:29","guid":{"rendered":"http:\/\/wordpress.cephas.net\/?p=649"},"modified":"2004-12-13T07:20:29","modified_gmt":"2004-12-13T11:20:29","slug":"automated-application-deployment-with-tomcat-part-ii-with-subversion-and-ant","status":"publish","type":"post","link":"https:\/\/cephas.net\/blog\/2004\/12\/13\/automated-application-deployment-with-tomcat-part-ii-with-subversion-and-ant\/","title":{"rendered":"Automated Application Deployment with Tomcat: Part II with Subversion And Ant"},"content":{"rendered":"<p>Got around to writing the deployment scripts that go with the <a href=\"http:\/\/subversion.tigris.org\/\">Subversion<\/a> work I did last week. As part of the scripts, I also worked on the problem I <a href=\"http:\/\/cephas.net\/blog\/2004\/11\/05\/automating_application_deployment_with_tomcat.html\">wrote about a couple weeks ago<\/a> (ie: needing different log4j properties files per environment).  Once you have a source control solution and a master build file, it&#8217;s pretty easy.  I stripped out the explicit log4j category and appender directives and instead used the Ant <a href=\"http:\/\/ant.apache.org\/manual\/OptionalTasks\/propertyfile.html\"><code>&lt;propertyfile&gt;<\/code><\/a> tag to write out the appropriate category \/ appender directives based on the presence (or lack thereof) of the <code>project.debug<\/code> property in my build file. When I want to create a build that outputs logging information to the console, this block of code is fired:<code><br \/>\n&lt;target name=\"build.resources.debug\" if=\"project.debug\"&gt;<br \/>\n&nbsp;&nbsp;&lt;propertyfile<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;file=\"WEB-INF\/classes\/log4j.properties\"&gt;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&lt;entry  key=\"log4j.rootCategory\" value=\"INFO, STDOUT\"\/&gt;<br \/>\n&nbsp;&nbsp;&lt;\/propertyfile&gt;<br \/>\n&lt;\/target&gt;<br \/>\n<\/code><br \/>\nOtherwise, this block is run:<code><br \/>\n&lt;target name=\"build.resources.production\" unless=\"project.debug\"&gt;<br \/>\n&nbsp;&nbsp;&lt;propertyfile<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;file=\"WEB-INF\/classes\/log4j.properties\"&gt;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&lt;entry  key=\"log4j.rootCategory\" value=\"ERROR, SMTPAPPENDER\"\/&gt;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&lt;entry  key=\"log4j.category.com.mycompany\" value=\"ERROR, SMTPAPPENDER\"\/&gt;<br \/>\n&nbsp;&nbsp;&lt;\/propertyfile&gt;<br \/>\n&lt;\/target&gt;<br \/>\n<\/code><br \/>\nIn Eclipse, you can easily create the <code>project.debug<\/code> property using the Arguments text box provided in Run &#8211;&gt; External Tools &#8211;&gt; $your ant build &#8211;&gt; Main Tab &#8211;&gt; Arguments: <code>-Dproject.debug=true<\/code>.  By default then, log4j will only log error conditions and will send them to the SMTP appender.  <\/p>\n<p>The second thing I did was to create a deployment Ant script that wrapped my main build.xml.  It checks out the source code from Subversion:<code><br \/>\n&lt;exec executable=\"svn\"&gt;<br \/>\n&nbsp;&nbsp;&lt;arg line=\"co svn:\/\/sourcecodeserver\/myproject\/branches\/v1.0 . --username username --password password\"\/&gt;<br \/>\n&lt;\/exec&gt;<br \/>\n<\/code>, runs the normal build:<code><br \/>\n&lt;ant antfile=\"build.xml\" \/&gt;<br \/>\n<\/code>, stops the Tomcat service:<code><br \/>\n&lt;exec executable=\"net\"&gt;<br \/>\n&nbsp;&nbsp;&lt;arg line='stop \"Apache Tomcat\"'\/&gt;<br \/>\n&lt;\/exec&gt;<br \/>\n<\/code>, deletes the existing web application from the Tomcat webapps directory:<code><br \/>\n&lt;delete dir=\"${tomcat.install}myapp\"\/&gt;<br \/>\n<\/code>, creates and unpacks the generated war to the Tomcat webapps directory:<code><br \/>\n&lt;mkdir dir=\"${tomcat.install}myapp\"\/&gt;<br \/>\n&lt;unzip src=\"myapp.war\" dest=\"${tomcat.install}myapp\"\/&gt;<br \/>\n<\/code> and then starts the Tomcat service:<code><br \/>\n&lt;exec executable=\"net\"&gt;<br \/>\n&nbsp;&nbsp;&lt;arg line='start \"Apache Tomcat\"'\/&gt;<br \/>\n&lt;\/exec&gt;<br \/>\n<\/code><br \/>\nWe&#8217;ll see how well it works once this goes into production.  If nothing else, at least I&#8217;ll have a couple more hours in my day.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Got around to writing the deployment scripts that go with the Subversion work I did last week. As part of the scripts, I also worked on the problem I wrote about a couple weeks ago (ie: needing different log4j properties files per environment). Once you have a source control solution and a master build file, &hellip; <a href=\"https:\/\/cephas.net\/blog\/2004\/12\/13\/automated-application-deployment-with-tomcat-part-ii-with-subversion-and-ant\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Automated Application Deployment with Tomcat: Part II with Subversion And Ant<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[3,2,12],"tags":[],"_links":{"self":[{"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/posts\/649"}],"collection":[{"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/comments?post=649"}],"version-history":[{"count":0,"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/posts\/649\/revisions"}],"wp:attachment":[{"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/media?parent=649"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/categories?post=649"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/tags?post=649"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}