Eclipse and Ant – They really get along very well!

Have you ever used your own custom ant task in the eclipse environment. Well – I have written some ant tasks and they are being used by all developers in our company. But there’s the annoying thing that I always have to add the libs containing my tasks to the classpath. Nothing easier than this you might be thinking. Add it to ants classpath in the eclipse preferences. This works on my machine but what about all other developers? What about updates to the libs?

I guess I found the perfect solution for this problem. Write an eclipse plug-in that adds all libraries to ants classpath using the extension point of the ant plug-in and put the plug-in on an eclipse site so all developers can get it automatically.

That’s easy to say but how? Lets get our hands dirty…

With the help of the “Eclipse Plug-in Development Tools” I create a new “Plug-in Project” using the wizard. For this plug-in I don’t even need a template.
The next step is adding the libs containing my ant tasks to the lib folder of the plug-in.
Now to use the extension point of eclipses ant plug-in the new plug-in must declare its dependencies.
Now the libs can be added as “extraClasspathEntries” in the “Extensions” tab.
The only thing left now is configuring the build to include the lib directory which contains the ant libs.

That’s it? Well let’s try it out. Right-click on the project and run-as “Eclipse Application”. Selecting Window->Preferences->Ant->Runtime all libs can be seen listed under “Contributed Entries”. *hurray*

To be really useful the plug-in has to be on an update-site which is being checked for updates automatically. How this is achieved will be the theme on a future post. If you can’t wait lets give you the short story – create a feature containing the plug-in, create an update-site and include your plug-in and install it on the clients… details later.

This was my first eclipse plug-in and I am really impressed. The features behind the eclipse plug-in architecture are really astonishing. The dependencies and extensions are very clear, the documentation is good and helpful and finally there are really useful wizards that do most of the job.
As for the plug-in: it proved really useful in production and already saved me hours (including development time). Now if something changes on an ant-task I just release a new version of the plug-in on the update site – done. And the best thing no developer can forget to add ant tasks to the classpath – its all done automatically.

About the author

Daniel Schröter

Add comment

By Daniel Schröter

Recent Posts