Monday, June 29, 2015

BeanShell - Java Scripting in Shell

BeanShell

  Ruby's IRB equivalent Java Scripting in console.

Home:
  http://www.beanshell.org/home.html


Get the latest beanShell jar file
   http://www.beanshell.org/download.html


To install as an extension place the bsh.jar file in your $JAVA_HOME/jre/lib/ext folder.

For Mac os: place the bsh.jar in /Library/Java/Extensions
( ~/Library/Java/Extensions for individual users)


CLASSPATH Update:
  unix:     export CLASSPATH=$CLASSPATH:bsh-xx.jar #update your bashrc
  windows:  set classpath %classpath%;bsh-xx.jar #update environment variables

NOTE: xx - should match you downloaded jar version


Start new Shell window

$ java bsh.Console # Starts bean console
$ java bsh.Interpreter   // run as text-only on the command line
$ java bsh.Interpreter filename [ args ] // run script file

Trial:
$ java bsh.Interpreter 
bsh %  int add(int a, int b) { return a+b;}
bsh % print(add(1,2)); //3

Manual
 http://www.beanshell.org/manual/bshmanual.html

No comments:

Post a Comment