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

Groovy Gears

Started from  http://www.groovy-lang.org/learn.html.

Decided to use GVM:

$ curl -s get.gvmtool.net | bash

  Installation went well; Updated bashrc and zshrc files.

  Started new shell window

$ gvm help # Showed help 

$ gvm install groovy #installed latest version

$ groovy -version # showed installed version


Create a (text) file hello_groovy
$ vim hello_groovy

Enter: System.out.println("Hello Groovy")
Save file

$ groovy hello_groovy #print "Hello Groovy"


Manual
http://www.vogella.com/tutorials/Groovy/article.html