wood burning stoves
The moose likes Java in General and the fly likes Using Java with an external scripting engine Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Using Java with an external scripting engine" Watch "Using Java with an external scripting engine" New topic

Using Java with an external scripting engine

Adam Nash

Joined: Jan 30, 2012
Posts: 1
Hello all - We have a requirement with one of our developments that I was hoping some of you Java Buffs could provide some ideas regarding an elegant solution.

We have a third party workflow system that we use with a number of our clients. This workflow system has a built in Javascript Engine that allows us to code some fairly simple conditional logic and updates. However, going forward the vendor has advised us to move away from using these Java Scripts and instead develop Custom Agents. Custom Agents are essentially Java Classes, and through them we are able to read and write Workflow Values.

The problem that we are facing is that we have a large number of Java Scripts, and we do not want to create separate Custom Agents for each. Instead the agreed solution will be to write a single Custom Agent (Java Class) that is capable of calling an external scripting engine, such as a VBS Script.

Calling a VBS Script from Java is fairly trivial, and we can easily pass in the dynamic variables by appending it to the command that starts the VBS Script. However the complication arises about getting the return variables, for which there may be a number of.

We have discussed two solutions so far:

1) The scripting logic is fairly simple, it is basic conditional branching and basic string and arithmetic manipulation Therefore we could write our own scripting parser. However, given the time-frames involved, this is our leased preferred option

2) We could write simple framework that calls a configurable VBS file, that additionally passes in the input fields, as well as the location of a temporary (and uncreated) text file. The VBS file would perform it's scripting duties, and additionally create and write the output values to that temporary text file. When control is passed back to Java, it would read the values from the text file, before deleting it. This solution would be much faster than #1, and would be beneficial in that the user could write the scripts in either VBScript or Javascript. However the idea of using text files to pass values back to the Custom Agent is clunky at best.

Does anyone here know of a more graceful solution? Are there any scripting engines that can handle passing values from and to Java classes in a much more elegant way? Or is there even a broader solution that I am overlooking?

Any feedback or advice would be greatly appreciated.

Many thanks
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
one way might be to write your custom
agent (CA) to check args.length at startup,
if 0, launch the vbscript file and close CA.
vbs does its stuff, then launches CA, this time supplying args (as strings), so now,
CA with args > 0, processes the args instead
of launching vbs.

sounds messy, but might work.
I agree. Here's the link: http://aspose.com/file-tools
subject: Using Java with an external scripting engine
It's not a secret anymore!