问题
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
回答1:
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.
回答2:
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
.
来源:https://stackoverflow.com/questions/14835882/apache-ant-gets-frozen-while-running-this-script