I did not learn how to create new instances of a java class in a jar file by java constructors, but accidentally discovered that it is very easy to use any static java methods to access Java objects in py2j.
step 1: download the py4j zip file from https://pypi.python.org/pypi/py4j . "py4j0.10.0.jar" is located in the zip file.
Step 2: install py4j with
pip install 'D:\Downloads\py4j-0.10.0.zip'
Step 3: add py4j0.10.0.jar as well as the_lib_you_use.jar (e.g. owlapi-distribution-3.5.0.jar for the example below) to create a path in the eclipse project
Step 4: create AdditionApplication.java and copy and paste the AdditionApplication.java code into https://www.py4j.org/ and run the Java application AdditionApplication.java
Step 5: after running AdditoinApplication.java check the sample code in the python file:
if __name__ == '__main__': pass from py4j.java_gateway import JavaGateway gateway = JavaGateway()
Result on the console:
(5, 0) 6 abcIRi = fewf
source share