Take the 2-minute tour ×

I want to show a password input dialog from ant script. Here's my code from build.xml:

<target name="sign" unless="isUpToDate">
    <script language="javascript">
        var pf = new JPasswordField();
        var okCxl = JOptionPane.showConfirmDialog(null, pf, "Enter Password", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);

        if (okCxl == JOptionPane.OK_OPTION) {
            project.setNewProperty("keypass", pf.getPassword());
        } else {
            throw "Password is required";
    <echo message="${keypass}"></echo>

This code hangs forever. What's wrong?

Update: I'm testing in Mac OS X 10.8.2 and Oracle JDK 7u13

share|improve this question
add comment

2 Answers

It works well in Eclipse Juno Release Build id: 20120614-1722 and JDK 7 under Windows XP:

Buildfile: D:\...\build.xml
     [echo] [C@ea1569
Total time: 7 seconds

And it works well from Run.bat :

D:\>call d:\ant\bin\ant
Buildfile: D:\...\build.xml

     [echo] [C@12a642

Total time: 8 seconds

But getPassword() returns char[] not String, this is because the echo is not human readable.

share|improve this answer
I tried both Indigo and Juno, but it does not work for me. I'm on Mac OS X 10.8.2 –  Antonio Feb 12 '13 at 15:54
Is Java in the PATH? Which version? –  Aerospace Feb 12 '13 at 15:55
Oracle JDK 7u13, no troubles with PATH –  Antonio Feb 12 '13 at 16:08
add comment

As an alternative, put the storepass required by <signjar /> in an invisible file, e.g. .deployconf, having user-only access: e.g. 400 or 600. Load the password in ant, and use as required:

<loadfile srcfile="${user.home}/.deployconf" property="deployconf"/>

This works well with <signjar />, although some effort may be required to keep linefeeds out of .deployconf.

share|improve this answer
add comment

Your Answer


