Ant2IDE – IDE project file generation from Ant build.xml

Ant2IDE generates Eclipse (or other IDE-specific) project files with proper classpath and source folder settings from Ant build.xml automatically.

I wrote ant2eclipse long time ago with my crude shell script skill to generate Eclipse project files from an Ant build.xml file.

In Ant2IDE, I extended the idea so that it works in a more elegant way using the BuildListener interface. The usage is pretty simple:

  1. Add ant2ide.jar to the classpath:
    export CLASSPATH="/usr/local/libexec/ant2ide.jar:$CLASSPATH"
  2. Change the working directory to the project home:
    cd /home/trustin/workspace/myAntProject
  3. Clean the build
    ant clean
  4. Run ant with the -listener option and appropriate task(s):
    ant -listener net.gleamynode.ant2ide.EclipseProjectGenerator compiile-main compile-test

You might prefer to use the following simple shell script:

# Path: /usr/local/bin/ant2eclipse
export CLASSPATH="$CLASSPATH:/usr/local/libexec/ant2ide/ant2ide.jar"
ant -listener net.gleamynode.ant2ide.EclipseProjectGenerator "$@"

How it works

How does Ant2IDE generate the Eclipse project files? It listens to the build events fired by Ant and records the source and destination directory of the javac tasks into its internal data structure. Once build is completed successfully, Ant2IDE processes the recorded information to generate IDE-specific project files. It’s very simple but it works much better than analyzing build.xml directly or creating a new Java project from an Eclipse workbench.


Of course, Ant2IDE is not a silver bullet – there’s some limitation in this approach.

First, you can’t get the correct build information unless you provide a proper Ant target. For example, clean target will never help AntIDE generate the project files. You should specify the target that compiles all source code, such as build-all or all, test-all.

Second, it doesn’t add all resource directories automatically. You have to add them manually for most cases. There’s no way to determine exactly whether a copy task copies resource files for now. One exception is when your project has a directory layout which is similar to that of Maven 2 project; Ant2IDE looks for a resources directory when the name of the source code directory is java, and add the resources directory to the source path automatically.

Third, Eclipse JDT is the only IDE that Ant2IDE supports at this moment. It’s designed to support other IDEs such as NetBeans and IntelliJ, but I don’t use them these days. Any contribution would be great.


  • Nov 19, 2008 – Added auto-detection of resources directory
  • Nov 14, 2008 – Initial implementation

23 Comments Ant2IDE – IDE project file generation from Ant build.xml

  1. Jan Matèrne

    Really a nice idea. What about not only extracting information from <javac> but also from <jar><war><ear>. Especially if <jar> contains a <manifest> for specifying a main-class there could be some valuable information.

  2. Robin Bramley

    Have just tried ant2ide to assist with a migrating a client codebase from IntelliJ to Eclipse…

    EclipseProjectGenerator doesn’t close the project description tag – line 67 needs to be:

  3. Ron Sigal


    I used Ant2IDE on the JBPAPP_4_3_0_GA_CP03 version of the JBoss Application Server, and I had to make only a few changes by hand.

    1. eclipse (I’m using ganymede) wasn’t happy with the the full pathnames in the .classpath file. I had to change, for example, “C:cygwinhomersigalworkspace.newEAP_4_3_0_GA_CP03thirdpartyapache-log4jliblog4j.jar” to “thirdpartyapache-log4jliblog4j.jar”

    2. The aspects module has some duplicate classes in aspects/src/jdk15 and aspects/src/main. I excluded the duplicate classes manually.

    3. In ejb3/build.xml, the “compile-classes” target has some directories excluded. I excluded them manually from the eclipse source path.

    4. iiop/src/main has a class, org.jboss.iiop.SunJDK14IsLocalBugFix, which won’t compile in the absence of its parent class. I excluded it manually.

    5. I didn’t run the tests, so the test modules didn’t get picked up. There was some dependency on remoting-int/src/main/tests, so I added it manually.

    Now that I know what the problems are, it should go a lot faster next time.

    Given the complexity of the JBossAS, I think Ant2IDE is pretty amazing.


  4. Rajarshi Nigam

    amazing, simply amazing. you’ve blown my mind, as well as several of my coworkers’ minds. much better and more flexible than Eclipse’s “new project from existing ant…”. how is this not part of Eclipse’s baseline?

  5. Trustin Lee

    @Ron Sigal: Hey, Ron! Thanks for sharing your experience on importing JBossAS using Ant2IDE. The first issue does seem to be a low-hanging fruit. I will fix it on my spare time. Other issues are somewhat difficult to fix and I think it needs human intervention, so I’d left them as a user’s labor. 😉

  6. marat

    Great tool!

    I wonder if you can make this tool’s source code available or at least compile it with an older javac – 1.4 so that people who are stuck with old javac can still use your tool!

    Don’t ask me why I cannot fork a new java instance in javac task 😉


  7. Fred Bulah

    Thanks a ton for sharing Trustin! I’m doing some WSDL work and needed a quick eclipse project for the generated WSDL2java code. Worked perfectly the first time.


Comments are closed.