Using Jython as a scripting engine in a project

Finally I have a proper usecase for using Jython as an integrated scripting engine in a Java-project. The opportunity came in a current project, where we do collaboration with third party who developes a certain calculation model which will be shared intellectual property between us and also released to the general public. Usage on Jython allows us to model the calculation model as python code, create it easily readable and runnable code on almost any and every desktop computer – and run the same code on our backend. Which is nice.

Based on the documentation and quick tests, integrating Jython is a snap and using JSR 233 or native interface are almost similar, though I’d prefer JSR 233 scripting api.

ScriptEngine engine = new ScriptEngineManager().getEngineByName("python");

TestObject foo = new TestObject();
foo.setName("Name of the object");
engine.put("foo", foo);
engine.eval(" = Changed name");
TestObject grab = (TestObject) engine.get("foo");

Works like a charm.

Kategoria(t): java, programming. Lisää kestolinkki kirjanmerkkeihisi.


Täytä tietosi alle tai klikkaa kuvaketta kirjautuaksesi sisään:

Olet kommentoimassa -tilin nimissä. Log Out / Muuta )


Olet kommentoimassa Twitter -tilin nimissä. Log Out / Muuta )


Olet kommentoimassa Facebook -tilin nimissä. Log Out / Muuta )

Google+ photo

Olet kommentoimassa Google+ -tilin nimissä. Log Out / Muuta )

Muodostetaan yhteyttä palveluun %s