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

Run Script from File Source 

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 interpreting beanshell script loaded from file source.

File Name  :  
/BEAN_SHELL001/config/print.bsh 
   
print(name)
print(date);
   

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

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Date;

import bsh.EvalError;
import bsh.Interpreter;

public class PrintVarScriptFileTest {

  /**
   @param args
   @throws EvalError 
   @throws IOException 
   @throws FileNotFoundException 
   */
  public static void main(String[] argsthrows EvalError, 
    FileNotFoundException, IOException {
    
    Interpreter interpreter = new Interpreter();  
    interpreter.set("name""Sriram");            
    interpreter.set("date"new Date())
    interpreter.source("C:/Temp/print.bsh");
  }

}
   

It gives the following output,
Sriram
Sun Dec 04 00:40:57 IST 2011



 
  


  
bl  br