tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Java Scripting > BeanShell > Get data from BeanShell

Get data from BeanShell 

BeanShell is a small, free, embeddable Java source interpreter with object scripting language features, written in Java. BeanShell is a natural scripting language for Java. This requires the library bsh-2.0b4.jar to be in classpath. The following example shows retrieving beanshell scripting variables from the interpreter in Java.

File Name  :  
/BEAN_SHELL001/config/circle_area.bsh 
   
print("Calculating Area");
area = Math.PI * Math.pow(radius, 2);
print("Area Calculation completed");
   

File Name  :  
com/bethecoder/tutorials/bean_shell/AccessFromAppTest.java 
Author  :  Sudhakar KV
Email  :  [email protected]
   
package com.bethecoder.tutorials.bean_shell;

import java.io.InputStreamReader;

import bsh.EvalError;
import bsh.Interpreter;

public class AccessFromAppTest {

  /**
   @param args
   @throws EvalError 
   */
  public static void main(String[] argsthrows EvalError {
    Interpreter interpreter = new Interpreter();  
    interpreter.set("radius"4);            

    InputStreamReader reader = new InputStreamReader(
        ScriptedMethodsTest.class.getClassLoader()
        .getResourceAsStream("circle_area.bsh"));
    interpreter.eval(reader);  
    
    Double area = (Doubleinterpreter.get("area");
    System.out.println("Area of Circle : " + area);
  }

}
   

It gives the following output,
Calculating Area
Area Calculation completed
Area of Circle : 50.26548245743669



 
  


  
bl  br