By Sundararajan-Oracle on Jan 29, 2016
Dynamic linker API for the Java platform (JEP 276) in JDK 9 Early Access defines dynamic linker API for the Java platform. Using this API, different language runtimes implemented for the Java platform can interoperate with each other.
- I downloaded Jython 2.7 standalone jar from jython.org.
- In Jython, all objects known to the Jython runtime are represented by instances of the class PyObject or one of its subclasses. So, we've to write a pluggable dynalink linker that can link objects of PyObject and subclasses for easier access. JythonLinkerExporter.java
- dynalink uses java.util.ServiceLoader mechanism to load pluggable linkers. We've to write a META-INF/services file jdk.dynalink.linker.GuardingDynamicLinkerExporter and put it linker jar.
- I wrote a nashorn script to compile the linker source and make a jar jython_linker.js
- In addition, jython_linker.js also runs a sample mixed language script in which Nashorn script accesses Python objects - jython_sample.js
My directory structure looks as follows:
With the above files in place, we just to have run the sample with this command:
The output looks as follows:
With Dynalink, different language runtimes can interoperate with each other! Have fun with mixed language programming on the Java platform!