Ant2IDE generates Eclipse (or other IDE-specific) project files with proper classpath and source folder settings from Ant
I wrote ant2eclipse long time ago with my crude shell script skill to generate Eclipse project files from an Ant
In Ant2IDE, I extended the idea so that it works in a more elegant way using the BuildListener interface. The usage is pretty simple:
- Add ant2ide.jar to the classpath:
- Change the working directory to the project home:
- Clean the build
-listeneroption and appropriate task(s):
ant -listener net.gleamynode.ant2ide.EclipseProjectGenerator compiile-main compile-test
You might prefer to use the following simple shell script:
#!/bin/sh # 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
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
- Nov 14, 2008 – Initial implementation