{"id":276,"date":"2010-07-22T11:05:35","date_gmt":"2010-07-22T11:05:35","guid":{"rendered":"http:\/\/www.scmgalaxy.com\/tutorials\/2010\/07\/22\/a-sample-ant-build-script-that-builds-a-war-file\/"},"modified":"2017-12-29T11:37:47","modified_gmt":"2017-12-29T11:37:47","slug":"a-sample-ant-build-script-that-builds-a-war-file","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/a-sample-ant-build-script-that-builds-a-war-file\/","title":{"rendered":"A sample Ant build script that builds a WAR file &#8211;  Guide"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4408\" src=\"http:\/\/www.scmgalaxy.com\/tutorials\/wp-content\/uploads\/2010\/07\/ant-build-script.png\" alt=\"ant-build-script-war-file\" width=\"600\" height=\"400\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2010\/07\/ant-build-script.png 600w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2010\/07\/ant-build-script-300x200.png 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/p>\n<p><strong>A sample Ant build script that builds a WAR file<\/strong><\/p>\n<p>&lt;project name=&#8221;MyWebApplication&#8221; basedir=&#8221;..&#8221; default=&#8221;install&#8221;&gt;<\/p>\n<p>&lt;!&#8211; project-specific variables &#8211;&gt;<br \/>\n&lt;property name=&#8221;jsp.dir.name&#8221; value=&#8221;myapp&#8221; \/&gt;<br \/>\n&lt;property name=&#8221;package.name&#8221; value=&#8221;${jsp.dir.name}.war&#8221; \/&gt;<br \/>\n&lt;property name=&#8221;webapp.dir&#8221; value=&#8221;\/Users\/al\/tomcat-6.0.16\/webapps&#8221; \/&gt;<\/p>\n<p>&lt;property environment=&#8221;env&#8221; \/&gt;<br \/>\n&lt;property name=&#8221;build.dir&#8221; value=&#8221;build&#8221; \/&gt;<br \/>\n&lt;property file=&#8221;${build.dir}\/build.${env.HOSTNAME}&#8221; \/&gt;<\/p>\n<p>&lt;property name=&#8221;lib.dir&#8221; value=&#8221;lib&#8221; \/&gt;<br \/>\n&lt;property name=&#8221;pages.dir&#8221; value=&#8221;pages&#8221; \/&gt;<br \/>\n&lt;property name=&#8221;src.dir&#8221; value=&#8221;src&#8221; \/&gt;<br \/>\n&lt;property name=&#8221;src.tests.dir&#8221; value=&#8221;src-tests&#8221; \/&gt;<br \/>\n&lt;property name=&#8221;resources.dir&#8221; value=&#8221;resources&#8221; \/&gt;<br \/>\n&lt;property name=&#8221;dest.dir&#8221; value=&#8221;target&#8221; \/&gt;<\/p>\n<p>&lt;!&#8211; put everything in a temp folder with the right structure during the build &#8211;&gt;<br \/>\n&lt;property name=&#8221;temp.dir&#8221; value=&#8221;temp&#8221; \/&gt;<br \/>\n&lt;property name=&#8221;temp.dir.web-inf&#8221; value=&#8221;${temp.dir}\/WEB-INF&#8221; \/&gt;<br \/>\n&lt;property name=&#8221;temp.dir.lib&#8221; value=&#8221;${temp.dir.web-inf}\/lib&#8221; \/&gt;<br \/>\n&lt;property name=&#8221;temp.dir.classes&#8221; value=&#8221;${temp.dir.web-inf}\/classes&#8221; \/&gt;<br \/>\n&lt;property name=&#8221;temp.dir.meta-inf&#8221; value=&#8221;${temp.dir}\/META-INF&#8221; \/&gt;<\/p>\n<p>&lt;property name=&#8221;package.file&#8221; value=&#8221;${dest.dir}\/${package.name}&#8221; \/&gt;<\/p>\n<p>&lt;path id=&#8221;build.class.path&#8221;&gt;<br \/>\n&lt;fileset dir=&#8221;lib&#8221;&gt;<br \/>\n&lt;include name=&#8221;**\/*.jar&#8221; \/&gt;<br \/>\n&lt;\/fileset&gt;<br \/>\n&lt;\/path&gt;<\/p>\n<p>&lt;target name=&#8221;clean&#8221;&gt;<br \/>\n&lt;delete&gt;<br \/>\n&lt;fileset dir=&#8221;${dest.dir}&#8221; includes=&#8221;**\/*&#8221;\/&gt;<br \/>\n&lt;\/delete&gt;<br \/>\n&lt;delete dir=&#8221;${temp.dir}&#8221; \/&gt;<br \/>\n&lt;delete dir=&#8221;${temp.dir.classes}&#8221; \/&gt;<br \/>\n&lt;delete dir=&#8221;${temp.dir.meta-inf}&#8221; \/&gt;<br \/>\n&lt;delete dir=&#8221;${temp.dir.web-inf}&#8221; \/&gt;<br \/>\n&lt;\/target&gt;<\/p>\n<p>&lt;target name=&#8221;prepare&#8221; depends=&#8221;clean&#8221;&gt;<br \/>\n&lt;mkdir dir=&#8221;${dest.dir}&#8221; \/&gt;<br \/>\n&lt;mkdir dir=&#8221;${temp.dir}&#8221; \/&gt;<br \/>\n&lt;mkdir dir=&#8221;${temp.dir.lib}&#8221; \/&gt;<br \/>\n&lt;mkdir dir=&#8221;${temp.dir.meta-inf}&#8221; \/&gt;<br \/>\n&lt;mkdir dir=&#8221;${temp.dir.web-inf}&#8221; \/&gt;<br \/>\n&lt;mkdir dir=&#8221;${temp.dir.classes}&#8221; \/&gt;<br \/>\n&lt;\/target&gt;<\/p>\n<p>&lt;!&#8211; COMPILE &#8211;&gt;<br \/>\n&lt;target name=&#8221;compile&#8221; depends=&#8221;prepare&#8221;&gt;<br \/>\n&lt;echo&gt;=== COMPILE ===&lt;\/echo&gt;<br \/>\n&lt;echo&gt;Compiling ${src.dir} files &#8230;&lt;\/echo&gt;<br \/>\n&lt;javac debug=&#8221;on&#8221; srcdir=&#8221;${src.dir}&#8221; destdir=&#8221;${temp.dir.classes}&#8221; includes=&#8221;**\/*&#8221;&gt;<br \/>\n&lt;classpath refid=&#8221;build.class.path&#8221; \/&gt;<br \/>\n&lt;\/javac&gt;<\/p>\n<p>&lt;!&#8211; compile files on the src-tests path &#8211;&gt;<br \/>\n&lt;echo&gt;Compiling ${src.tests.dir} files &#8230;&lt;\/echo&gt;<br \/>\n&lt;javac debug=&#8221;on&#8221; srcdir=&#8221;${src.tests.dir}&#8221; destdir=&#8221;${temp.dir.classes}&#8221; includes=&#8221;com\/**&#8221;&gt;<br \/>\n&lt;classpath refid=&#8221;build.class.path&#8221; \/&gt;<br \/>\n&lt;\/javac&gt;<br \/>\n&lt;\/target&gt;<\/p>\n<p>&lt;!&#8211; PACKAGE &#8211;&gt;<br \/>\n&lt;target name=&#8221;package&#8221; depends=&#8221;compile&#8221;&gt;<br \/>\n&lt;echo&gt;=== PACKAGE ===&lt;\/echo&gt;<\/p>\n<p>&lt;!&#8211; copy the config files &#8211;&gt;<br \/>\n&lt;copy file=&#8221;${resources.dir}\/MANIFEST.MF&#8221; tofile=&#8221;${temp.dir.meta-inf}\/MANIFEST.MF&#8221; overwrite=&#8221;true&#8221; \/&gt;<br \/>\n&lt;copy file=&#8221;${resources.dir}\/web.xml&#8221; tofile=&#8221;${temp.dir.web-inf}\/web.xml&#8221; overwrite=&#8221;true&#8221; \/&gt;<br \/>\n&lt;copy file=&#8221;${resources.dir}\/managed-beans.xml&#8221; tofile=&#8221;${temp.dir.web-inf}\/managed-beans.xml&#8221; overwrite=&#8221;true&#8221; \/&gt;<br \/>\n&lt;copy file=&#8221;${resources.dir}\/navigation-rules.xml&#8221; tofile=&#8221;${temp.dir.web-inf}\/navigation-rules.xml&#8221; overwrite=&#8221;true&#8221; \/&gt;<\/p>\n<p>&lt;copy todir=&#8221;${temp.dir.classes}&#8221;&gt;<br \/>\n&lt;fileset dir=&#8221;${src.dir}&#8221;&gt;<br \/>\n&lt;include name=&#8221;**\/*.xml&#8221;\/&gt;<br \/>\n&lt;include name=&#8221;**\/*.xsl&#8221;\/&gt;<br \/>\n&lt;\/fileset&gt;<br \/>\n&lt;\/copy&gt;<\/p>\n<p>&lt;!&#8211; with all resources in place, create the war file &#8211;&gt;<br \/>\n&lt;war destfile=&#8221;${package.file}&#8221; webxml=&#8221;${temp.dir.web-inf}\/web.xml&#8221; basedir=&#8221;${temp.dir}&#8221;&gt;<br \/>\n&lt;fileset dir=&#8221;${pages.dir}&#8221;\/&gt;<br \/>\n&lt;lib dir=&#8221;${lib.dir}&#8221; \/&gt;<br \/>\n&lt;classes dir=&#8221;${temp.dir.classes}&#8221; \/&gt;<br \/>\n&lt;\/war&gt;<br \/>\n&lt;\/target&gt;<\/p>\n<p>&lt;!&#8211; JUST DEPLOY JSP&#8217;s &#8211;&gt;<br \/>\n&lt;target name=&#8221;jsps&#8221;&gt;<br \/>\n&lt;echo&gt;=== DEPLOY JSP&#8217;S ===&lt;\/echo&gt;<br \/>\n&lt;!&#8211; i&#8217;m trying to be explicit about what i put out there &#8211;&gt;<br \/>\n&lt;copy todir=&#8221;${webapp.dir}\/${jsp.dir.name}&#8221;&gt;<br \/>\n&lt;fileset dir=&#8221;${pages.dir}&#8221;&gt;<br \/>\n&lt;include name=&#8221;**\/*.jsp&#8221;\/&gt;<br \/>\n&lt;include name=&#8221;**\/*.html&#8221;\/&gt;<br \/>\n&lt;include name=&#8221;**\/*.css&#8221;\/&gt;<br \/>\n&lt;include name=&#8221;**\/*.gif&#8221;\/&gt;<br \/>\n&lt;include name=&#8221;**\/*.jpg&#8221;\/&gt;<br \/>\n&lt;include name=&#8221;**\/*.png&#8221;\/&gt;<br \/>\n&lt;include name=&#8221;**\/*.js&#8221;\/&gt;<br \/>\n&lt;\/fileset&gt;<br \/>\n&lt;\/copy&gt;<br \/>\n&lt;\/target&gt;<\/p>\n<p>&lt;!&#8211; INSTALL &#8211;&gt;<br \/>\n&lt;target name=&#8221;install&#8221; depends=&#8221;package&#8221;&gt;<br \/>\n&lt;echo&gt;=== INSTALL ===&lt;\/echo&gt;<br \/>\n&lt;copy file=&#8221;${package.file}&#8221; tofile=&#8221;${webapp.dir}\/${package.name}&#8221; overwrite=&#8221;true&#8221; \/&gt;<br \/>\n&lt;\/target&gt;<\/p>\n<p>&lt;\/project&gt;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A sample Ant build script that builds a WAR file &lt;project name=&#8221;MyWebApplication&#8221; basedir=&#8221;..&#8221; default=&#8221;install&#8221;&gt; &lt;!&#8211; project-specific variables &#8211;&gt; &lt;property name=&#8221;jsp.dir.name&#8221; value=&#8221;myapp&#8221; \/&gt; &lt;property name=&#8221;package.name&#8221; value=&#8221;${jsp.dir.name}.war&#8221; \/&gt; &lt;property name=&#8221;webapp.dir&#8221; value=&#8221;\/Users\/al\/tomcat-6.0.16\/webapps&#8221; \/&gt;&#8230; <\/p>\n","protected":false},"author":1,"featured_media":4408,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[2],"tags":[209,3827,4215,4212,4214,4209,4211,4216,4213,4219,378,4210,1122,3113,593,4218,213,4217],"class_list":["post-276","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorised","tag-ant","tag-ant-build","tag-ant-build-script","tag-ant-build-script-for-war-file","tag-ant-script-to-build-war-file","tag-ant-war-task","tag-ant-war-task-meta-inf-example","tag-build-war-file","tag-build-war-file-using-ant","tag-build-war-file-with-ant","tag-commands","tag-create-war-file-using-ant-command","tag-guide","tag-how-to","tag-process","tag-sample","tag-tutorial","tag-war-file"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/276","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=276"}],"version-history":[{"count":2,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/276\/revisions"}],"predecessor-version":[{"id":4410,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/276\/revisions\/4410"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media\/4408"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=276"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=276"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=276"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}