Apache Ant gets frozen while running this script

2019-03-05 22:12发布

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">
        importClass(javax.swing.JPasswordField);
        importClass(javax.swing.JOptionPane);
        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";
        }
    </script>
    <echo message="${keypass}"></echo>
    ...
</target>

This code hangs forever. What's wrong?

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

2条回答
够拽才男人
2楼-- · 2019-03-05 22:36

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

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

And it works well from Run.bat :

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

sign:
     [echo] [C@12a642

BUILD SUCCESSFUL
Total time: 8 seconds

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

查看更多
对你真心纯属浪费
3楼-- · 2019-03-05 22:42

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.

查看更多
登录 后发表回答