在Java应用中使用BeanShell(2.0b41)的简单示例
来源:互联网 发布:finale2016打谱软件 编辑:程序博客网 时间:2024/06/05 00:17
1. 在工程中导入jar包:bsh-2.0b4.jar
2. 示例代码:
package com.huey.dream.bsh;import java.io.FileNotFoundException;import java.io.IOException;import java.util.Date;import bsh.EvalError;import bsh.Interpreter;/** * 使用BeanShell的简单示例 * @author huey * @version 1.0 * @created 2014-11-14 */public class BshApp {public static void main(String[] args) {// 创建一个bsh脚本解释器Interpreter interpreter = new Interpreter();try {interpreter.eval("which(java.lang.String);");// 设置变量,然后执行bsh脚本interpreter.set("date", new Date());interpreter.eval("print(date)");// 执行bsh脚本,然后获取变量interpreter.eval("foo = \"Hello World\"");String foo = (String) interpreter.get("foo");System.out.println(foo);// 加载脚本文件并执行boolean result = (Boolean) interpreter.source("src/hello.bsh");System.out.println(result);} catch (EvalError e) {e.printStackTrace();} catch (FileNotFoundException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();}}}
3. 脚本文件hello.bsh:
add(a, b) {return a + b;}print(add(1, 2));print(add("Bean", "Shell"));return true;
0 0
- 在Java应用中使用BeanShell(2.0b41)的简单示例
- 怎样在osworkflow中使用BeanShell
- 怎样在osworkflow中使用BeanShell
- 怎样在Beblogic中使用BeanShell
- 怎样在osworkflow中使用BeanShell
- beanshell简单使用
- 在项目中简单使用枚举的示例代码
- BeanShell快速入门---Java应用
- beanshell的使用
- Java中使用AES加密的简单示例
- BeanShell 在 JMeter中的使用
- atitit.bsh BeanShell 的动态脚本使用java
- Jmeter-BeanShell的使用介绍
- Jmeter-BeanShell的使用介绍
- java中随机函数的使用及简单应用
- 在win32应用中使用printf代码示例
- zTree在asp.net中读取数据库简单使用示例
- 在python中使用c语言扩展模块的简单示例
- Android:新浪微博拉起客户端分享——完美实现同时分享图片和文字(Intent.ACTION_SEND)
- utl_file包的使用
- 51单片机之大杂烩
- XCode 快捷键
- Eclipse中注释复用
- 在Java应用中使用BeanShell(2.0b41)的简单示例
- 关于block的实现和注意
- android enter 隐藏输入法
- JSP内置对象request中的getParameter()和getAttribute()方法的区别
- Font Awesome 4.2.0 Icon
- gnome-logs开发记录3--修复bug726228+杂记
- 二叉树的建立和基本操作
- iOS开发:设计模式那点事
- cocos2dx 3.x 中 Lua socket 和 node.js 利用scoket互相通信读写二进制数据