Creating an ANT file from an existing Java project

Strongback Consulting

Sometimes we need to more tightly control the build process within our projects. When using Eclipse or Rational Application Developer, the IDE controls how the project is compiled through the properties screens (which ultimately are written back to property files).

However, what if you need to use the same build steps you use in Eclipse in an automated build system like Hudson, Jenkins, or (my favorite) Team Concert? Well, you can create an ANT file from an existing Eclipse based project easily, but not intuitively.

Right click on your project and select ‘Export’. In the dialog that follows, select ‘ANT Buildfile’ file.

Generate ANT file from project

Then, select your target projects from the list. You can specify the name of the build file (defaults to build.xml), and the target directory of JUnit. 

Then, click finish. 
Now, you can open your file and edit it directly. The next step would be to replace the builders for the project.
To do that, right click on your project and select ‘Builders’. Click the ‘New’ button, and select ‘ANT Builder’. Then point to the ANT file you just created. Now your project will build based off that ANT file. Depending upon what other builders are in place here, you could remove the others, but I recommend you be judicious here. Some of those builders are validators that help you the developer be productive. Keep those, as well as those that are tied to custom plugins. Your ANT file should be able to stand on its own to do a reliable compilation however. Now, you can add WAR/EAR or packaging targets, and even deployment targets as needed. This will allow the script to be used by your continuous integration system to automatically build the project. If you use a 2 phase or 2 step approach, this means your file can do step1 (compile / unit test). If that passes, a post deploy task can deliver to another stream, where it will package and deploy the application to an integration server for QA testing. 
Helpful resources here:

Comments are closed.

Strongback Consulting