简体   繁体   English

Apache Ant在运行此脚本时被冻结

[英]Apache Ant gets frozen while running this script

I want to show a password input dialog from ant script. 我想从ant脚本中显示一个密码输入对话框。 Here's my code from build.xml : 这是我在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 更新:我正在使用Mac OS X 10.8.2和Oracle JDK 7u13进行测试

It works well in Eclipse Juno Release Build id: 20120614-1722 and JDK 7 under Windows XP: 它在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

And it works well from Run.bat : 它从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. 但是getPassword()返回char []而不是String,这是因为echo不是人类可读的。

As an alternative, put the storepass required by <signjar /> in an invisible file, eg .deployconf , having user-only access: eg 400 or 600 . 作为替代方案,将<signjar />所需的storepass放在一个不可见的文件中,例如.deployconf ,具有用户访问权限:例如400600 Load the password in ant , and use as required: ant加载密码,并根据需要使用:

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

This works well with <signjar /> , although some effort may be required to keep linefeeds out of .deployconf . 这适用于<signjar /> ,尽管可能需要一些努力来保持.deployconf换行符。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM