How to call java objects and functions from CPython?

后端 未结 6 725
栀梦
栀梦 2020-12-13 22:05

I have a python program, which runs on the CPython implementation, and inside it I must call a function defined in a java program. How can I do this?

It would be nic

6条回答
  •  再見小時候
    2020-12-13 22:44

    If you don't want to go the write your own JNI/C route.

    The other option is to use jpype which for me is always what I use to access Oracle databases becuase installing the oracle c drivers on a PC is a pita. You can do stuff like (from docs):

     from jpype import * 
     startJVM("d:/tools/j2sdk/jre/bin/client/jvm.dll", "-ea") # or path to your jvm
     java.lang.System.out.println("hello world") 
     shutdownJVM()
    

    It hasn't been updated in a while and there isn't much in the way of documentation but it does work reasonably well.

    • homepage
    • docs

提交回复
热议问题