Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 9 Current »

Description

The Jython plugin enables compiling and running Jython code on your Griffon application.

Installation

The current version of griffon-jython-plugin is 0.3

To install just issue the following command:

Usage

You must place all Jython code under $appdir/src/jython, it will be compiled first before any sources available on griffon-app or 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.

$appdir/src/jython/griffon/JythonGreeter.py

Where 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 "classpath*:/jython/*/.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 griffon.jython.dynamicPropertyName.

Scripts

  • create-jython-class - creates a new Jython class in $basedir/src/jython.
  • create-jython-script - creates a new Jython script in $basedir/griffon-app/resources/py.
  • jython-repl - executes a Jython REPL with the application's classpath fully configured.

Source Code

Maintained on GitHub at the griffon-jython plugin repository.

History

Version

Date

Notes

0.303-12-12Griffon 0.9.5+ compatibility

0.2

08-15-11

Griffon 0.9.2 compatibility

0.1

01-04-11

Initial release

  • No labels