Ant and Eclipse Best Practices Question…

So I have an Ant & Eclipse best practices question. I’m not sure on the appropriate way of integrating Ant into my Eclipse projects.

Here is the background. When I create a new project I always have Eclipse split my source and output into separate folders. Eclipse defaults to ${}/bin and I normally change it to classes. Anyhow, obviously one of the great features of Eclipse is that it always is looking over your shoulder and checking your code as you type character after character. Letting you know when you miss a semi-colon, or junk like that. So you see you’ve done something wrong and you quickly go back and fix it and then keep coding.

Now because most projects don’t stay on development boxes people use Ant and write build.xml scripts to do all kinds of stuff related to their projects. They use Ant for building output dirs, compiling code, creating jar/war files, and sometimes even deploying applications. Obviously, Ant doesn’t just do this stuff for you, like Eclipse does, you have to run Ant and tell it what you want done.

Now, we’re getting to my best practice question(s) for integrating Ant into an Eclipse project. What should I be doing with the Eclipse output dir when I create a project? Should it be set to the same thing I set as my destdir in my build.xml file? I’ve played with this a bit and it seems to make Eclipse act strange. As certain Ant tasks are removing output dirs for clean builds I can see Eclipse wanting to do it’s “continuous build” thing and recompile my code.

The other way to do this would be let Eclipse compile your code to it’s standard bin directory and then use Ant with whatever output directory you set in your build.xml. That method seems like the one that would make Eclipse the happiest, but then you’ve got twice the class files sitting in your project and one of those feelings that “this just isn’t the right way to do things”….

There is one other way to do this and it’s the least appealing option to me. That is just disable the Eclipse “auto-compile” feature and run the Ant compile target in my build.xml.

Anyhow, I’d love to know what other people out there think. I’ve read a great article on OnJava about “Ant Best Practices” but it didn’t mention anything about Ant inside Eclipse.

This Post Has 2 Comments

  1. Rob

    My vote is to have seperate output folders, to keep your ant build completely IDE independant. Eclipse and Ant just don’t like playing together, and I think the purposes of the two output folders are really different. With Ant you are usually packaging, deploying, running metrics or something “one-off” like that. With Eclipse you are constantly making changes as you code. So keep em seperate.

  2. Erik Weibust

    Howdy Rob,

    I like your logic for keeping seperate build dirs and until I hear a strong argument for using one dir I’m also using seperate output/build dirs.


Leave a Reply