17

Sorry, I'm not terribly experienced with Ant.

I like the eclipse "Export ant buildfile" function, but I need to insert a few custom tasks (Copying files, calculating checksums that are used at runtime, etc).

How do I integrate custom ant tasks with the antfile that Eclipse exports? Also, once I've done so, will the internal build (Run...) pick it up or will I always have to use the external ant file to build from now on?

Oh, and I don't want to edit the build.xml that is exported from Eclipse, because I'd like to be able to regenerate it later.

Edit/Update:

It took me a while to figure out what was going on--so I thought I'd put some notes here to clarify.

When you create a new ant file in your directory and put <?eclipse.ant.import ?> on the first line of your custom ant script (I called mine test.xml), next time you export the buildfile from Eclipse into that directory, it'll see that tag and add <import file="test.xml"/>

With that Import, the targets in your "Custom" file (test.xml) become valid targets in your exported build.xml (or whatever name you chose when you exported it).

After this, anytime you select "build.xml" in Eclipse, the targets pane will also include targets from "test.xml"

Also, after that, you can go into your project properties/Builders and add a new builder of type "Ant Build", then select targets to use for building, clean, etc.

Bill K
  • 62,186
  • 18
  • 105
  • 157
  • 2
    I have tried this on Eclipse 3.4.1 and figured out, that my custom build file was only included when its name started with build. For example, build-custom.xml was imported correctly, but custom_build.xml was ignored... Maybe this helps anyone... – Martin Klinke Feb 11 '09 at 15:43
  • Same with me, I am using Eclipse 3.5.2 on Ubuntu, and had to rename my file to build-custom.xml instead of custom-build.xml – Marthinus Nov 06 '10 at 19:35

4 Answers4

13

The ant export filter will include any xml file in the same directory which has the special

<?eclipse.ant.import?>

element as its first child.

Example:

<?xml version="1.0" encoding="UTF-8"?>
<?eclipse.ant.import?>
<project name="project" default="default" basedir=".">
    ...
</project>

Eclipse will now include the following line in build.xml:

<import file="custom_build.xml"/>
moomoohk
  • 483
  • 1
  • 8
  • 23
JesperE
  • 63,317
  • 21
  • 138
  • 197
  • Geocities is gone, so find the example [here](http://timealias.bplaced.net/eclipse2ant/doc/build-user.xml) and the site [here](http://timealias.bplaced.net/eclipse2ant/) – Derek Thurn Sep 19 '10 at 23:28
  • 4
    @Derek all examples are gone, can you please include the examples again? – Saba Ahang Nov 03 '14 at 09:20
  • @JesperE What values should be assigned to the name and default? Also, I want this target (say targetA) to depend on another target (say targetB) defined in the main build.xml file but eclipse shows an error saying that the targetB doesn't exists in this project. – Bikash Gyawali Sep 21 '16 at 10:11
2

If you write your own Ant script, you can write your own targets that use the Ant task to delegate to the generated build.xml.

Also, you can configure a project's 'builders' (project properties » Builders) to run any something different when you build the project, manually or automatically.

martin clayton
  • 76,436
  • 32
  • 213
  • 198
Peter Hilton
  • 17,211
  • 6
  • 50
  • 75
1

PDE has support for custom callbacks from the generated build.xml into your own custom ant script.

Copy the file "templates/plugins/customBuildCallbacks.xml" from the org.eclipse.pde.build in your eclipse install, and set "customBuildCallbacks=true" in your build.properties file.

See also the Eclipse help page

Andrew Niefer
  • 4,279
  • 2
  • 19
  • 22
0

You can have a separate ant build file for these tasks. Thats all you need.

Rob Ottaway
  • 614
  • 5
  • 9