The Jython plugin enables compiling and running Jython code on your Griffon application.
The current version of griffon-jython-plugin is 0.2
To install just issue the following command:
You must place all Jython code under
$appdir/src/jython, it will be compiled first before any sources available on
src/main which means you can't reference any of those sources from your Jython code, while the Groovy sources can. You will be able to use the LangBridge Plugin facilities to communicate with other JVM languages.
Sources placed under
$appdir/src/jython will generate Java classes available for use within griffon-app.
IGreeter is an interface allowing Jython to expose methods:
This will generate a Java class named
griffon.JythonGreeter, which can be used inside any Griffon artifact, for example a Controller
You are also able to load Jython scripts at any time. By default all scripts placed at
$basedir/griffon-app/resources/jython will be loaded when the application boostraps itself. For example
griffon-app/resources/jython/fib.py might look like this:
With that code in place, the addNumbers function may be executed as a method call on a dynamic property named
py from a Griffon controller. See below:
The dynamic property will be named
py by default. The name of the property may be set explicitly in
griffon-app/conf/Config.groovy by assigning a value to the griffon.jython.dynamicPropertyName property.
For most applications, the default name of
py should be fine. You can also alter in which artifacts the property gets injected, by default only controllers will have that property. See
griffon-app/conf/Config.groovy and look for the following entry
Finally, you can load any Jython script by calling
pyLoad(String path) where
path will be resolved using Spring's PathMatchingResourcePatternResolver. The default path used during bootstrap is
.py". It is also worth mentioning that this method will be injected to all artifacts controlled by
griffon.jython.injectInto and that the prefix
py will be affected by
- create-jython-class - creates a new Jython class in
- create-jython-script - creates a new Jython script in
- jython-repl - executes a Jython REPL with the application's classpath fully configured.
Maintained on GitHub at the griffon-jython plugin repository.
Griffon 0.9.2+ compatibility