Technical topics (hopefully) explained in plain language.

Friday, December 5, 2008

Password prompting in Ant

Sometimes you've just gotta prompt for info in Ant. Everything can't go in config files-- passwords, for example.

The problem is, for things like passwords we'd really like to not have Ant echo what we're typing.

It turns out that in Ant 1.7.1 they added a "SecureInputHandler" which does this (it takes advantage of some things in Java 1.6). It's not documented, exactly, but its in there:

<target name="input-test" >
<input message="username:>" addproperty="username" defaultvalue="lalala" />

<input message="password:>" addproperty="password">
<handler classname="org.apache.tools.ant.input.SecureInputHandler" />
</input>

<echo message="username= ${username}" />
<echo message="password= ${password}" />
</target>

No comments:

Blogger Syntax Highliter