DevOps / BeanShell Interview questions
How do you embed BeanShell in a Java application?
Add the BeanShell library (the bsh jar) to the application's classpath, then create an instance of bsh.Interpreter in Java code - from that point, the host application can call eval() on it to run script strings or source() to run script files.
Variables can be passed from the host application into the script's namespace using the Interpreter's set() method, and values can be pulled back out of the script's namespace into the host application using get(), giving a two-way bridge between compiled Java code and interpreted script code.
This pattern is exactly what tools like JMeter use internally: the host application creates an Interpreter, exposes its own relevant objects into that Interpreter's namespace, runs the user's script, and then reads back whatever result or side effect the script produced.
More Related questions...