Monthly Archives: August 2011

Script variables

In my previous post, I showed how the parameters to a JavaScript function can be supplied with Java. The next step is to supply other variables. The simplest way to set some variable values is to use ScriptEngine.put(name, value): ScriptEngine engine = …; engine.put(“taxRate”, 0.0825); // 8.25% // evaluate script // invoke function Now the [...]

Invoking a function defined in JavaScript

Picking up where I left off in the previous post, I am going to cover some ways to get data into a script. Here’s how to simply supply parameter values when calling a function defined in a script. First the ScriptRunner needs to be updated: pubic class ScriptRunner { … public void load(String scriptName) throws [...]

Running a JavaScript file from Java

I gravitate towards writing testing infrastructure. I find it very rewarding to see my frameworks, abstractions and convenience APIs being used by my coworkers. As the testing gets further and further away from unit tests, having scripting capabilities tends to become increasingly important. In the past, I’ve used BeanShell, jython and various DSLs to support [...]

Follow

Get every new post delivered to your Inbox.