Over the past two months, there have been a few good articles written on the concept of using Jython within Java apps without utilizing the jythonc utility. This is, in fact, the best way to invoke Jython code within a Java app.
Read more about using this technique in these articles written for the Jython Monthly newsletter.
Accessing Jython from Java Without Using Jythonc
Simple and Efficient Jython Object Factories
It is possible to use Scripting (JSR-223 - javax.script) API with Jython (or any of the other supported languages - please refer to http://scripting.dev.java.net). There is javax.script.Invocable interface. Invocable.getInterface method(s) support getting a Java interface implementation - either implemented by script global functions or implemented by methods of a script object. The script author need *not* implement interface explicitly -- just need to have methods of matching names. Also, this solution does not require Jython embedding API calls in Java side - and more importantly the solution works for any jsr-223 scripting language. So, the Java side can switch b/w Jython and other languages in one place - place where ScriptEngineFactory is obtained.
ReplyDelete