Howardism Musings from my Awakening Dementia
My collected thoughts flamed by hubris
Home PageSend Comment

Working with Ant in Eclipse

Most of the Ant work that I do just works in Eclipse. The integration is quite nice. But there is one aspect that I would have assumed would have just be set up, but it isn't.

If you try to execute a task, and it claims that it isn't around with the following message:

      Could not create task or type of type: junit.

Ant could not find the task or a class this task relies upon.

This is common and has a number of causes; the usual 
solutions are to read the manual pages then download and
install needed JAR files, or fix the build file: 
 - You have misspelt 'junit'.
   Fix: check your spelling.

And the error message goes on with lots of information that really doesn't point you in the direction of getting this to work in Eclipse. Granted, it may actually work from the command line.

The trick is to tell Eclipse about the task. To do this, choose the menu item Window | Preferences…. In the dialog, select the Ant | Runtime panel. Now click on the Tasks tab.

Screenshot 1

Now click the Add Task… button. Fill in the name, "junit" and select the "ant-junit.jar" file under Location field. No, you still aren't done yet. You now have to hunt down through the directory hierarchy for the JunitTask.class file, as in this diagram:

Screenshot 2

Now the Ant processes started from Eclipse will be able to execute the <junit> tasks, but it still needs access to the JUnit library. You might as well add it to your $ANT_HOME/lib directory, but for this to work, you can put it anywhere.

In Eclipse (in that same Ant | Runtime panel), select the Classpath tab and while selecting the "Global Entries" item, click on the *Add External JARs… button. Wander around your file system until you find that JAR and select it.

Screenshot 3

This same sort of procedure can be applied to get the <scp> task to work, however, for this guy to work, you are going to also have to add the JSch library. To do this, go to the website and download the Jar file, and follow the steps mentioned above.

You should be able to now execute those Ant tasks from inside Eclipse.

Tell others about this article:
Click here to submit this page to Stumble It