Introduction

Why Ant4Eclipse?

We all know this situation: the developers of a team are using the Eclipse IDE to code their apps, to compile their apps, to version, to deploy, and to run their apps. No problems so far. But as soon as you want to set up something like a continuous build system which runs outside of Eclipse you also need a build process that is independent of Eclipse. Usually you will use Ant and some other tools to define your automatic build process. Fine. But unfortunately Ant cannot use any of Eclipse's configurations, such as classpathes, launcher or team project sets. Although everything has been nicely configured already inside the IDE, it has to be redone in those external Ant build files. And even worse: it has to be reconfigured each time a developer makes changes in Eclipse. As always with redundant data, the challenge is to keep Eclipse and Ant configurations in sync. But how about avoiding redundancy in the first place? This is where ant4eclipse comes into play.

The solution: ant4eclipse

The aim of the ant4eclipse project is to avoid (or at least: to reduce) the redundancy of Eclipse and Ant configurations. More precisly: it consists of Ant tasks that are able to read and work with some of Eclipse's configuration files. With these tasks you are for example able to:

  • setup Ant classpathes as defined in Eclipse .classpath-file
  • checkout complete workspaces as it's possible with the Team Project Set feature of eclipse
  • build Eclipse plug-ins and OSGi bundles

With all these tasks you're able to create a complete automatic build system that starts with checking out all required projects from CVS, builds all projects in the correct order with classpath settings as specified in Eclipse, and to launch your applications as they are specified in Eclipse. And the best of it: if you or someone else changes a configuration in Eclipse, those changes are immediately visible to your buildfiles - without changing one line of code!

Installation

Add all required JARs to ANT's classpath

Before you can use ant4eclipse within your ant files, you have to add the org.ant4eclipse_<version>.jar JAR and all the JARs contained in the libs directory of the ant4eclipse distribution to the ant4eclipse classpath. This can be done in any of the following ways (take a look at the Ant manual for further information):

  • Installing ant4eclipse to Ant's lib-directories
    This is the easiest way of installing ant4eclipse. Simply copy the org.ant4eclipse_<version>.jar and the jars from the libs directory from the ant4eclipse distribution into the lib directory of your ant installation. An alternative approach is to copy the jar files to a directory called .ant/lib in your home directory. Both directories will be searched by Ant for libraries.
  • Using ant4eclipse from command line
    Add the org.ant4eclipse_<version>.jar and the jars from the libs directory from the ant4eclipse distribution to the classpath by using Ant's "-lib" command line argument:
     ant -lib /path/to/ant4eclipse/ant4eclipse.jar -lib /path/to/ant4eclipse/libs <other ant args>; 

Add ant4eclipse's tasks in your build file

After you have installed ant4eclipse, you can create a new build.xml file and add the tasks that come with ant4eclipse using Ant's taskdef task:

<project ...
         xmlns:ant4eclipse="antlib:org.ant4eclipse"
         xmlns:antcontrib="antlib:net.sf.antcontrib">

	<taskdef uri="antlib:net.sf.antcontrib"
	         resource="net/sf/antcontrib/antlib.xml" />

	<taskdef uri="antlib:org.ant4eclipse"
	         resource="org/ant4eclipse/antlib.xml" />
  ...

</project>

Note that you can not use the classpath argument of the taskdef task (otherwise the EJC compiler adapter won't work). You must make sure that ant4eclipse is included in ant's classpath as described above. If you want to edit your build files from Eclipse include the jars that comes with ant4eclipse in the Eclipse Ant runtime environment at Window -> Preferences -> Ant -> Runtime -> Global Entries. See the following screenshot for an example (Of course you have to adjust the path settings for your environment):