How to use java classes from BeanShell

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

How to use java classes from BeanShell


I am new using BeanShell. I am writing a driver and an graphic client for this driver so that I can install the driver on a computer connected directly to the device and the graphic client on other computer which should communicate with the driver over internet using Beanshell.

So when the client wants to know the state of the device it sends a string "isConnected()" to get the result of "device.isConnected()", the driver executes something like this:

Device device = new Device(); //Device is a class which contains a function "isConnected()"
Interpreter interpreter = new Interpreter();
interpreter.set("device", device);

But this returns an eval exception.

How can I load a variable into the interpreter and later execute its functions from Beanshell?
If I can do that, the variable will reflect its changes if it is changed from java?

I would appreciate any help, thank you.