File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Ant, Maven and Other Build Tools and the fly likes Using ANT to deploy Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Using ANT to deploy" Watch "Using ANT to deploy" New topic

Using ANT to deploy

Ruturaj Waghmode

Joined: Dec 22, 2008
Posts: 2
I'm trying to automate our deploy process using ANT (since we using it for our build & ideally want to keep everything in ANT).
For Deployment, I intend to store environment info in properties file, which ANT can fetch values from for each environment.
However, found out that once a property value has been set in ANT, you can't change it i.e. can't use an ANT property as a variable.

Any tips or alternatives to solve this would be appreciated.

Sample of what I'm trying to achieve. In real life, my sequence would be, read env1 properties, deploy, read env2 properties, deploy & so on.

<project name="RutuTest" default="build">
<target name="build">

<property name="temp" value="1" />
<echo message="temp = ${temp}" />
<property name="temp" value="2" />
<echo message="temp = ${temp}" />

Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17410

There's several ways to to this, but here's 2 I like to use:

1. Specify the build environment on the command line:

ant -Dbuild.type=test

Note that I also have global and local property files here to allow additional specialized builds. As always, whoever sets a property first, wins.

Another way is essentially a variant of this. Make "build-development", "build-test", and "build-production" goals (or however you like) in the build.xml file. Set the properties in these goals, then use Antcall to recurse on Ant as though you'd set them on the command line. This can be good if you have lots of properties to set (but not enough to warrant an extra properties file). And, people don't have to know what the exact values to put on the original Ant command line are, since it doesn't need "-D" settings.

An IDE is no substitute for an Intelligent Developer.
Ruturaj Waghmode

Joined: Dec 22, 2008
Posts: 2
Thanks. I'll try your option# 2 which looks feasible.
I agree. Here's the link:
subject: Using ANT to deploy
It's not a secret anymore!