0

我想显示来自 ant 脚本的密码输入对话框。这是我的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>

此代码永远挂起。怎么了?

更新: 我正在 Mac OS X 10.8.2 和 Oracle JDK 7u13 中进行测试

4

2 回答 2

1

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.

于 2013-02-12T16:59:28.603 回答
1

它在 Eclipse Juno Release Build id: 20120614-1722 和 Windows XP 下的 JDK 7 中运行良好:

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

它在 Run.bat 中运行良好:

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

sign:
     [echo] [C@12a642

BUILD SUCCESSFUL
Total time: 8 seconds

但是getPassword()返回 char[] 而不是 String,这是因为 echo 不是人类可读的。

于 2013-02-12T15:46:53.740 回答