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

Special Variables 

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 accessing special variables in beanshell script.

File Name  :  
/BEAN_SHELL001/config/special_vars.bsh 
   
print("bsh.cwd : " + bsh.cwd);
print(this.caller)
print(this.callstack);
   

File Name  :  
com/bethecoder/tutorials/bean_shell/SpecialVariablesTest.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 SpecialVariablesTest {

  /**
   @param args
   @throws EvalError 
   */
  public static void main(String[] argsthrows EvalError {
    Interpreter interpreter = new Interpreter();
    InputStreamReader reader = new InputStreamReader(
        SpecialVariablesTest.class.getClassLoader()
        .getResourceAsStream("special_vars.bsh"));
    
    interpreter.eval(reader);
  }

}
   

It gives the following output,
bsh.cwd : C:\BTC\BEAN_SHELL001

'this' reference (XThis) to Bsh object: NameSpace: 
	Called from compiled Java code. (bsh.NameSpace@e4f972) (method) 

CallStack:
	NameSpace: print (bsh.NameSpace@1bf52a5) (method) 
	NameSpace: global (bsh.NameSpace@1cafa9e)



 
  


  
bl  br