When executing an Ant build from within your Eclipse-based IDE, you cannot expect your project's libraries to be on the Ant classpath. You may get several Ant build errors. From within Eclipse, Ant uses its own unique classpath which is easily configured. This article describes how.
You can execute an Ant build from within Eclipse by right-clicking on the build file and selecting Run As > Ant Build. However, the classpath for Ant does not automatically match that of your project. So, commonly, you will get a BUILD FAILED with several 'does not exist' or 'cannot find symbol' errors in the console similar to what you see below.

These errors appear because Ant uses its own unique classpath when executed from within Eclipse. Similar to the way that you put libraries on the classpath for your project, you must also put them on the classpath for Ant. Here's how...
Open the Eclipse Preferences dialog and select Ant > Runtime. In the Classpath tab, select the Global Entries item where you can then add your libraries. You can see, for example, that I have added Log4J to my Global Entries as an External JAR.

That's it. When you've added all required libraries as Global Entries, you should be able to get a successful Ant build from within Eclipse.

3 Comments
comments.show.hideAug 07, 2008
Anonymous
That's kind of lame. I would not qualify that as a Jedi trick but as a trick for people who does not know his tools.
What about making ant read the class path instead so you don't have to maintain 2 classpath lists?
Ant4Eclipse is one example.
Aug 07, 2008
Cody Burleson
Because this tip describes how to use the Ant system that is within Eclipse. It does not share the classpath of your project - nor is your project's classpath global to your system. I don't understand what you are saying. If you're going to call it lame, back it up with some examples or something. Teach me what your talking about because I don't quite understand what you've said.
I've never heard of Ant4Eclipse - maybe it is a better way to use Ant from within Eclipse. Thanks for the tip! I'll check it out and if it is indeed a better approach, I'll modify the document.
Dec 31, 2009
Anonymous
Thank you, this helped me get my ant build script working!
Ant4Eclipse also looks good, but it seems it doesn't support JavaSE6 yet.