Tutorial

This is a short overview on building a project with ant4eclipse. It shows how to setup ant4eclipse and how to use it in your ant-buildfile. This step-by-step tutorial requires eclipse 3.1 or newer. Although ant4eclipse works with eclipse 3.0, the tutorial won't, because it requires the RCP Mail Template, which is only available in 3.1 or newer.

Step 1: Install ant4eclipse

Download a copy of the ant4eclipse-plugin and unzip it to your eclipse installation. Start (or restart) eclipse. To verify your installation, select 'Windows -> preferences'. In the Treeview, select 'ant -> runtime'. The ant4eclipse-classpathentry should be listed in "Contributed Entries".

The entries contributed by the ant4eclipse plugin

Step 2: Create simple RCP Mail Application

Create simple RCP Mail Application as described in "Create an RCP Template". After creating the example application, your workspace should look like the workspace shown below.

The example workspace

Step 3: Setup your ant-buildfile

Now create a new file called build.xml (or download it here: build.xml), which is your antfile to build the application. To use ant4eclipse in your antscript, you have to define it via the tasdef-task:

<project name="com.example.xyz" default="build">
<!-- define ant4eclipse -->
  <taskdef resource="net/sf/ant4eclipse/antlib.xml" />
</project>
			

Add the following fragment to define the workspace directory and the projectname:

<property name="workspace" value="${basedir}/.." />
<property name="project.name" value="com.example.xyz" />
   

Because the example project references plugins which have to be resolved during the build, you have to specify the so-called targetPlatformLocation. This is the location where your eclipse installation is located and where ant4eclipse can find the necessary plugins. Note that you have to change this entry so that it points to your eclipse installation:

<property name="targetPlatformLocation" value="R:/software/ide/eclipse32"/>
   

Finally, add the build target which builds the application. The build target uses several ant4eclipse-Tasks to resolve project informations from the underlying .project- and .classpath-files:

<target name="build">

  <!-- resolve the eclipse output location -->
  <getOutputpath property="classes.dir" workspace="${workspace}" projectName="${project.name}" />

  <!-- init output location -->
  <delete dir="${classes.dir}" />
  <mkdir dir="${classes.dir}" />

  <!-- resolve the eclipse source location -->
  <getSourcepath property="source.dir" workspace="${workspace}" projectName="${project.name}" />

  <!-- read the eclipse classpath -->
  <getEclipseClasspath pathId="build.classpath" targetPlatformLocation="${targetPlatformLocation}"
                          workspace="${workspace}" projectName="${project.name}" />

  <!-- compile -->
  <javac srcdir="${source.dir}" destdir="${classes.dir}" classpathref="build.classpath" />

  <!-- copy resources from src to bin -->
  <copy todir="${classes.dir}" preservelastmodified="true">
    <fileset dir="${source.dir}">
      <exclude name="**/*.java" />
    </fileset>
  </copy>

</target>

You can now simply start the build by executing the build.xml with the Ant-Launcher!

The console output from the successful build