- Introduction to Java enabled Python
- Using Jepp to call Java from Python
Introduction to Java enabled Python
There are different methods to combine Python and Java. A quick overview:
- Python also know as CPython is the original implementation of the Python programming language.
- Jython is an implementation of the Python programming language in 100% Pure Java and seamlessly integrated with the Java platform. It thus allows you to run Python on any Java platform.
- Jepp - Java Embedded Python embeds CPython in Java and gives access to the high quality Python modules, both native and Python-based.
- JPype is an effort to allow python programs full access to java class libraries.
Jepp and JPype both allow the usage of Java libraries from within Python code. The JPype project started very recently so use here the Jepp project.
There are two incompatibilities between current Jython and CPython versions. First, Jython 2.2 does not implement any features added to CPython in version 2.3 or later. This includes language features such as decorators, and library modules such as
optparse. A more modern version of Jython is under active development. Second, Jython programs cannot use CPython extension modules written in the C programming language. These modules usually have files with the extension
.dll. If you want to use such a module, you should look for an equivalent written in pure Python or Java.
Using Jepp to call Java from Python
- Java (JRE or JDK)
This example creates a new Product and fills its only band with a linear gradient.
This could be adapted to write from exiting code into the BEAM-DIMAP data format.
To execute this Python script you need a batch script(on Windows) or a shell script (on Unix) to start the JVM with right classpath. It must contain the BEAM and the JEPP libaries.
This script gets as its first argument the name of the Python script to execute. The product writing script from above is called with: