Ant Command Line Wrapper
Summary
This is an Apache Ant command line wrapper similar to the Gradle command line wrapper.
It provides an antw
command wrapper to ant
that will auto-download and build your project for a requested Apache Ant version.
This ensure that as long as your build file is good, other people will be able to build your project easily with no prior Apache Ant setup.
What can you do with it?
- You can generate an Ant wrapper for a project from a machine with an existing Ant installation.
- You can share the project without requiring an existing Ant installation from the ‘application builder’.
The wrapper functionality is provided via a custom Apache Ant task.
Notes
- This project was only tested with Apache Ant 1.7.0 and above, under Mac OSX, Linux and Windows.
- The tool has not been tested with very complex builds where many classloaders could be involved.
Building the program
You’ll need a recent Apache Ant version (Only tested with Ant 1.7.0 and above).
From the project directory, run the following command to build the jar file:
ant
You can also generate the Ant wrapper for the project itself!
ant wrapper
Once the wrapper is installed, you can play with it, as you please:
./antw -projecthelp
Integration
Using Apache Ivy (Recommended)
If your Ant build already uses Apache Ivy as dependency manager, take a look at the ant-wrapper-example.
If you don’t want to use Ivy, you can follow one of the 2 next approaches, after copying the ant-wrapper
jar ‘somewhere’.
The build process will generate the resulting jar
archive in the project dist
folder.
You have 2 installation options:
- Drop the jar at the root of your existing projects or any other given location (Ant taskdef with classpath).
- Drop the jar in your
ANT_HOME/lib
folder (ant taskdef without any classpath setup).
Download the Ant task Jar file from Maven central using the link below.
Using AntLib
It’s also possible to use Antlib and XML namespaces to refer to the Ant wrapper custom task.
<?xml version="1.0"?> <project name="AntWrapperProject" xmlns:wrapper="antlib:com.rimerosolutions.ant.wrapper.tasks" default="wrapper"> <!-- The optional Ant Task also accepts a baseDistributionUrl properties for the Ant zip files binaries --> <!-- if you dropped the wrapper jar in ANT_HOME/lib --> <taskdef uri="antlib:com.rimerosolutions.ant.wrapper.tasks" resource="com/rimerosolutions/ant/wrapper/tasks/antlib.xml"/> <!-- if you have the wrapper jar at the root folder of your project <taskdef uri="antlib:com.rimerosolutions.ant.wrapper.tasks" resource="com/rimerosolutions/ant/wrapper/tasks/antlib.xml" classpath="ant-wrapper-0.0.1.jar"/> --> <target name="wrapper"> <wrapper:wrapper/> <!-- <wrapper:wrapper baseDistributionUrl="http://archive.apache.org/dist/ant/binaries"/> antVersion="1.8.0"/> --> </target> </project>
Sample build script (no Antlib)
<?xml version="1.0"?> <project name="AntWrapperProject" default="wrapper"> <!-- The optional Ant Task also accepts a baseDistributionUrl properties for the Ant zip files binaries --> <!-- if you dropped the wrapper jar in ANT_HOME/lib --> <taskdef name="genAntWrapper" classname="com.rimerosolutions.ant.wrapper.tasks.AntWrapperTask"/> <!-- if you have the wrapper jar at the root folder of your project <taskdef name="genAntWrapper" classname="com.rimerosolutions.ant.wrapper.tasks.AntWrapperTask"> <classpath> <pathelement location="ant-wrapper-0.0.1.jar"/> </classpath> </taskdef> --> <target name="wrapper"> <genAntWrapper/> <!-- <genAntWrapper baseDistributionUrl="http://archive.apache.org/dist/ant/binaries" antVersion="1.8.0"/> --> </target> </project>
Wrapper generation
With the above sample script, accordingly to the taskdef approach that you selected, run the following:
ant wrapper
This will create 5 main artefacts at the root of your project folder :
- antw : A UNIX command wrapper.
- antw.bat : A Windows command wrapper.
- antw.cmd : Environment variable helper for Windows.
- lcp.bat : The usual Windows classpath utility script.
- wrapper : A folder containing the launcher supporting files.
Testing
- Run your current project via the Ant wrapper instead of your local Ant installation.
- Build your project with the Ant wrapper on a machine that doesn’t have an existing Ant installation.
Task properties
name | Description | Value |
---|---|---|
baseDistributionUrl | The download base distribution URL | The default value is : http://archive.apache.org/dist/ant/binaries |
antVersion | The ant version to use for the wrapper | The default value is auto-detected unless specified. |