Generate Python bindings (wrappers) on Java Classes.
- Generates Intellisense friendly Python bindings on Java Classes.
- Bindings are based on Pyjnius.
- Compatible with Python 3.
- Supports overriding of Java Classes and Interfaces from Python.
- Callbacks to Python from Java.
The j2pBindCLI can be used to generate Python bindings using java .class files.
java -jar j2pBindCLI-0.1.0-SNAPSHOT-jar-with-dependencies.jar [path to root directory of compiled classes] [output path]
*Note: First follow the instructions in How to Install
section.
This example code extends a Java Class using a Python Class.
- Create a directory for example code. (say
example_code_directory
) - Create the subdirectory structure
example_code_directory/java/test
. - Copy TestClass.java to
example_code_directory/java/test
.- Note that TestClass is a Java Class belonging to package test.
- It is an abstract class with abstract methods.
- Compile TestClass.java.
javac TestClass.java
- Navigate to
source_directory/j2pBindCLI/target
and runjava -jar j2pBindCLI-0.1.0-SNAPSHOT-jar-with-dependencies.jar example_code_directory/java example_code_directory
.- Now you have python bindings generated for TestClass.java.
- Copy TestApp.py to
example_code_directory/python/
.- TestApp.py has class TestClassImpl which extends TestClass.java.
- It overrides some of the methods of the extended Java class.
- Run
python3 TestApp.py
- This executes a sequence of method calls with print lines explaining the control flow.
- Install dependencies
- Java 8.0+ with maven
- Python 3.5
- Cython
sudo pip3 install cython
- Pyjnius
sudo pip3 install pyjnius
- Clone the project and navigate to source directory
- Run
mvn clean install
- If the build succeeds, j2pBindCLI would be located at j2pBindCLI/target directory.
- Static functions support
- Fields support
- Maven binding generator plugin