开发者

how can i use alertbox concept of javascript in ant script

i m using like following for generating alertbox in ant script.

<target name="javascript">
        <script language="javascript">
<![CDATA[   
importPackage(java.lang);          开发者_Go百科 
alert("I am alert menu!");
</script>           
]]>        
</target>

but it's not working. showing following error

javax.script.ScriptException: sun.org.mozilla.javascript.internal.EcmaError: ReferenceError: "alert" is not defined. (#4) in at line number 4

pls anyone help me out.


If you have swing, then you can do something like this:

<script language="javascript">
<![CDATA[
    importPackage(javax.swing);
    JOptionPane.showMessageDialog( 'Title', 'I am alert menu!' );
]]>
</script>

Based on this source.

edit

I can't quite see what is causing the error in your sample, but the below works for me. Note that you can't use null for the first argument to the JOptionPane dialog - the compiler can't disambiguate the two two-arg constructors if you try that.

<target name="speed">
<script language="javascript">
<![CDATA[
    importPackage(javax.swing);
    var optionPane = JOptionPane.showInputDialog( 'Speed in miles per hour?', '10' );
    var mph = parseFloat(optionPane);
    var kph = 1.621 * mph;
    JOptionPane.showMessageDialog( null, 'KPH = ' + kph );
]]>
</script>
</target>

I get a modal input dialog "Input" with label "Speed in miles per hour?" and initial value "10". Then this response:

how can i use alertbox concept of javascript in ant script


To display a message you can use ants "exec" - to execute a shell command. On Linux that command would be "zenity", see: http://en.wikipedia.org/wiki/Zenity

On Windows ... well you can install zenity for windows: http://www.placella.com/software/zenity/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜