<dependency>
<groupId>org.beanshell</groupId>
<artifactId>bsh</artifactId>
<version>2.1.0</version>
</dependency>
import bsh.Interpreter;
public class Main {
public static void main(String[] args) throws Exception {
Interpreter interpreter = new Interpreter();
interpreter.eval("result = 2 + 3;");
Object result = interpreter.get("result");
System.out.println("Result: " + result);
}
}
public class Calculator {
public static int add(int a, int b) {
return a + b;
}
}
result = Calculator.add(2, 3);
import bsh.Interpreter;
public class Main {
public static void main(String[] args) throws Exception {
Interpreter interpreter = new Interpreter();
interpreter.eval("import com.example.Calculator;");
interpreter.source("calculator.bsh");
Object result = interpreter.get("result");
System.out.println("Result: " + result);
}
}