2

I am working on some Java projects and using ant to build my projects. The environment and the project structure is such that I cannot use any IDE.

Hence, I am looking for a good tool that can generate build.xml files to be used with ant (if possible something similar to autotools for c++).

Ankit
  • 6,772
  • 11
  • 48
  • 84
  • 1
    Related http://stackoverflow.com/questions/4185921/any-way-to-generate-ant-build-xml-file-automatically-from-eclipse – Santosh Jan 09 '12 at 10:51
  • 1
    If you want automatisation, **maven** would be a replacement of **ant**, worth investigating. Especially as it builds on "best practices" and conventions. It also does dependency management (like **ivy** for use with ant). – Joop Eggen Jan 09 '12 at 10:54
  • If your build is such that an automated tool can generate your build.xml, then I agree with Joop, Maven is a better choice. It uses convention over explicit configuration, and makes dependency management a breeze. – Danny Thomas Jan 09 '12 at 11:48

2 Answers2

3

No such thing as a "standard" ANT file. This makes it difficult to develop a generic ANT file generator. Course there's nothing stopping you from writing one yourself (simplified example below)

Don't forget that ANT is very cross-platform, unlike make. This might explain the lack of tools equivalent to autotools.

Simple ANT file generator

This example uses a simple template file called build.xml.template:

<project name="%PROJECT_NAME%" default="helloworld">

    <target name="helloworld" description="Pretty pointless ANT target">
        <echo message="%MESSAGE%"/>
    </target>

</project>

The UNIX sed command can then be used to substitute values and generate the ANT file:

$ sed -e 's/%PROJECT_NAME%/hello world/' -e 's/%MESSAGE%/hello world/' build.xml.template

This is a really simple generator. I'd suggest investigate a proper template engine for a more powerful solution.

Alternatives

Maven

As suggested in other answers, Maven can be used to generate new projects:

$ mvn archetype:generate

Still end up with a rather complex XML based file that might need further tweaking.

Gradle

If you're looking for a Java build tool with a simple build specification, nothing beats Gradle.

build.gradle:

apply plugin: 'java'

All you need is to compile a Java project with no external dependencies.

Lucky
  • 16,787
  • 19
  • 117
  • 151
Mark O'Connor
  • 76,015
  • 10
  • 139
  • 185
0

I work a lot in ANT but I always write build.xml manually in edit plus.

dinesh028
  • 2,137
  • 5
  • 30
  • 47