[Ant] Build .WAR files in Eclipse for Web Applications

Ant build file that helps you to quickly build a WAR file is here. It assumes the standard directory structure, so it will work on your project mostly without any change.

Eclipse JEE versions support Java Web Application projects, but other Eclipse versions do not. Java developers need to build WAR (web archive) files for deployments (yes, Exploded deployments are also possible). However Eclipse does not provide a direct way to create war files; developers write ant build files for this. So we thought of sharing a generic ant build file for Web Applications.

Our general Web Application's folder structure is shown in the image. In most cases, this structure will exactly match t your project structure; however the folder named "WebRoot" may be different to yours. (If your folder structure is different, let us know in comments section).

Ant Build file (build.xml)

Following is the general ant build file (build.xml).
<project name="MyWebApplication" basedir="." default="archive">

    <property name="WEB-INF" value="${basedir}/WebRoot/WEB-INF" />
    <property name="OUT" value="${basedir}/out" />
    <property name="WAR_FILE_NAME" value="mywebapplication.war" />
    <property name="TEMP" value="${basedir}/temp" />

    <target name="help">
            compile - Compile
            archive - Generate WAR file

    <target name="init">
        <delete dir="${WEB-INF}/classes" />
        <mkdir dir="${WEB-INF}/classes" />

    <target name="compile" depends="init">
        <javac srcdir="${basedir}/src"

    <target name="archive" depends="compile">
        <delete dir="${OUT}" />
        <mkdir dir="${OUT}" />
        <delete dir="${TEMP}" />
        <mkdir dir="${TEMP}" />
        <copy todir="${TEMP}" >
            <fileset dir="${basedir}/WebRoot">
        <move file="${TEMP}/log4j.properties"
              todir="${TEMP}/WEB-INF/classes" />
        <war destfile="${OUT}/${WAR_FILE_NAME}"
             webxml="${TEMP}/WEB-INF/web.xml" />
        <delete dir="${TEMP}" />

    <path id="libs">
        <fileset includes="*.jar" dir="${WEB-INF}/lib" />


You can go through the above xml file and see the process; we have created an attribute for WAR file's name.
<property name="WAR_FILE_NAME" value="mywebapplication.war" />

You should change the value "mywebproject.war" to match your project name. Save the above build.xml file inside Web applications project folder as shown in the folder structure image.

Ant build file has separate tasks for compiling the project and to build the war file. In Eclipse you just have to right click on this build file and select "Ant Build" to execute it. The war file will be generated and stored inside <web-project>/out folder.



About,2,Adsense,3,Ant,1,Apache,3,Axis,3,Blogger,1,Books,1,CentOS,2,Chrome,2,CSS,2,Database,3,Earn Online,3,Eclipse,10,Facebook,1,Firefox,10,Gmail,4,GNU/Linux,9,Google,26,GWT,8,Hardware,2,IE,5,Interesting,15,Internet,14,Java,49,Javascript,7,JBoss,1,Jenkins,1,Log4j,2,Me,6,Microsoft,2,Miscellaneous,1,News,11,Opinion,10,OSGi,1,PHP,1,Productivity,3,Programming,36,Puzzle,3,Security,4,Software,41,Sports,9,Spring,2,Story,6,Subversion,3,TDD,4,Tech,2,Tips,1,Tomcat,6,Tutorial,13,Ubuntu,4,Web application,14,Web Design,2,Web services,3,Windows,10,Yahoo,1,Zip,2,
Digizol: [Ant] Build .WAR files in Eclipse for Web Applications
[Ant] Build .WAR files in Eclipse for Web Applications
Ant build file that helps you to quickly build a WAR file is here. It assumes the standard directory structure, so it will work on your project mostly without any change.
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS CONTENT IS PREMIUM Please share to unlock Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy