星空网 > 软件开发 > Java

atitit.bshBeanShell的动态脚本使用java

atitit.bsh BeanShell 的动态脚本使用java

 

 

1.1. BeanShell是一个小巧免费的JAVA源码解释器

,支持对象式的脚本语言特性,亦可嵌入到JAVA源代码中。

亦可嵌入到JAVA源代码中,能动态执行JAVA源代码并为其扩展了脚本语言的一些特性,像JavaScript和perl那样的弱类型、命令式、闭包函数等等特性都不在话下

 

BeanShell能理解标准的JAVA语句,表达式,和方法宣告。语句和表达式的内容可以是:变量,宣告,赋值,方法调用,循环,条件等。
在 Java程序中你必须严格的使用它们,但在BeanShell中,你可以用“宽松类型”(loosely typed)的方式来使用它们。也就是说,你可以在写脚本时偷懒,不进行变量类型的宣告(在原始数据类型和对象都可以)。如果你试着用错变量类 型,BeanShell将会给出一个错误。

作者:: 绰号:老哇的爪子 ( 全名::Attilax Akbar Al Rapanui 阿提拉克斯 阿克巴 阿尔 拉帕努伊 ) 汉字名:艾龙,  EMAIL:1466519819@qq.com

转载请注明来源: http://www.cnblogs.com/attilax/

 

2. 运行方式:

l 界面UI方式 :java bsh.Console

l 命令行方式 :java bsh.Interpreter

l运行脚本文件:java bsh.Interpreter filename [ args ]

3. BeanShell将成为Java平台上的第三种编程语言

JCP接纳了一个新的技术规范进入标准化进程,这个编号为JSR-274的技术规范将把BeanShell引入为Java平台上支持的又一种编程语言。

JSR- 274(http://jcp.org/en/jsr/detail?id=274)是由 Patrick Niemeyer提交的技术规范,其目标是将BeanShell脚本语言(http://www.beanshell.org/)规范化为Java虚拟机 平台上支持的第三种编程语言。除了Java之外,Java虚拟机还支持Groovy脚本语言。Doug Lea、Apache和Google三个JCP执委会成员对此规范表示了支持。

按照Java最初的设计思路,有很多语言都可以在JVM上 运行(详细列表参见http://en.wikipedia.org/wiki/List_of_Java_scripting_languages), 但这些语言大多没有流行起来。直到2004年为止,Java平台事实上只有一种编程语言,也就是Java。2004年3月,Groovy(JSR- 241)成为了Java平台上的第二种编程语言。

3.1. Define  method

3.2. Scripted Methods

You can declare and use methods in BeanShell just as you would in a Java class.

 

int addTwoNumbers( int a, int b ) {

    return a + b;

}

 

sum = addTwoNumbers( 5, 7 );  // 12

 

Bsh methods may also allow dynamic (loose) argument and return types.

 

add( a, b ) {

    return a + b;

}

 

foo = add(1, 2);            // 3

foo = add("Oh", " baby");   // "Oh baby"

 

3.3. Implementing Interfaces

Note: implementing arbitrary interfaces requires BeanShell be run under a Java 1.3 or higher environment.

You can use the standard Java anonymous inner class syntax to implement an interface type with a script. For example:

 

ActionListener scriptedListener = new ActionListener() {

    actionPerformed( event ) { ... }

}

 

You don't have to script all of the methods of an interface. You can opt to script only those that you intend to call if you want to. The calling code will simply throw an exception if it tries to invoke a method that isn't defined. If you wish to override the behavior of a large number of methods - say to produce a "dummy" adapter for logging - you can implement a special method signature: invoke(name, args) in your scripted object. The invoke() method is called to handle any undefined method invocations:

 

ml = new MouseListener() {

    mousePressed( event ) { ... }

    // handle the rest

    invoke( name, args ) { print("Method: "+name+" invoked!");

}

 

 

4. Refe

 

BeanShell(JAVA源码解释器)_百度百科.htm

BeanShell快速入门---Java应用程序脚本引擎 - Love program - BlogJava.htm

Quick Start.htm

Embedding BeanShell in Your Application.htm

BeanShell Commands Documentation.htm

 




原标题:atitit.bshBeanShell的动态脚本使用java

关键词:JAVA

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

谷歌挖煤工闻焦焦:https://www.goluckyvip.com/tag/31911.html
谷歌外贸seo:https://www.goluckyvip.com/tag/31912.html
谷歌外贸推广:https://www.goluckyvip.com/tag/31913.html
谷歌网络推广:https://www.goluckyvip.com/tag/31914.html
谷歌引流:https://www.goluckyvip.com/tag/31915.html
谷歌引流教程:https://www.goluckyvip.com/tag/31916.html
黄仁勋问答全文:关于中国市场、全球供应链、奥特曼和Groq :https://www.kjdsnews.com/a/1836443.html
200万上下文!月之暗面Kimi又长长长了:一次处理500个文件 还能读懂甄嬛传 :https://www.kjdsnews.com/a/1836444.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流