I would like to run class imported from different beanshell file. But I've no idea how instantiate class from main beanshell file. Is this possible?
Class which I import:
class HelloW {
public void run(){
print("Hello World");
}
}
Main beanshell file which should run and instantiate class:
Interpreter i = new Interpreter();
i.source("HelloW.bsh");
The BeanShell documentation is pretty good in this area, so you should read through that first. In your case there are few issues. That said, there are Scripted Objects. Also, the .bsh file you start with needs to execute the scripted object. Taking your example this code should work:
*UPDATED answer for version BeanShell 2.0b1 and later which support scripted classes *:
I created two beanshell files and placed them in a directory "scripts".
The first "executor.bsh" is what you are calling the "parent" script, I believe.
The second file contains the scripted class. Note that I am using a Scripted Command and according to BeanShell documentation, the file name must be the same as the command name.
I invoked executor.bsh in a java class with:
Note that I left some commented code which also shows me executing the scripted class from Java, using Reflection. And this is the result: