You must have Javascript enabled to experience this site.

Eclipse2ant – export project settings to Ant build file

Posted & filed under Coding Tips.

This small plug-in has been in the official Eclipse build since version 3.1, however it is not easy to find or obvious how it can be used.


There are two ways of invoking it:

File → Export → General / Ant Buildfiles

Right click on project → Export → Export → General / Ant Buildfiles


A dialog will then prompt for the project and output file (usually build.xml). Pressing Finish will create the output file containing a complete Ant build description of the project.

While this is a great starting point, the build file does not do anything more than the internal Eclipse automatic build process would. Usually you want to package or deploy your project after building it and it would be useful if this could be part of this build process.

The solution is to include the automatically generated build file into a larger Ant build file. This way your custom project build can make use of the automatically generated build file with minimum maintenance.

My JSPServlet example contains two Ant build files: build.xml which has been automatically generated by Eclipse2ant and is used without modification; and build_war.xml which contains custom code to build the project into a WAR file for deployment.



<?xml version="1.0" encoding="UTF-8"?>
 * Build the WAR file
 * copyright Paul Shipley, Australia, 2011
 * @author Paul Shipley (pshipley @
 * @version $Id: build_war.xml 29 2012-02-14 00:57:09Z paul $
<project name="build_war" default="build_war" basedir=".">
    <!-- build war using build.xml which was created by eclipse2ant -->
    <import file="build.xml" />

    <property name="src" location="src" />
    <property name="wardir" location="." />
    <property name="warfile" location="${wardir}/JSPServlet.war" />

    <!-- common part for all projects, no editing beyond this line required -->
    <target name="build_war" description="build war" depends="clean,build,war" />

    <target name="clean">
        <ant antfile="build.xml" target="clean" inheritall="false" />
        <delete file="${warfile}" />

    <target name="war">
        <war destfile="${warfile}" webxml="WebContent/WEB-INF/web.xml" update="true">
            <classes dir="build/classes" />
            <classes dir="${src}" casesensitive="false">
                <include name="**/*.java" />
            <fileset dir="WebContent">
                <exclude name="WEB-INF/web.xml" />


Running this with Ant will process the automatically generated build file to compile the project then create the WAR file for deployment. This approach could be adopted to implement any build process you required such as creating a JAR file or deploying to a server.