Pyjnius import jar file

拜拜、爱过 提交于 2020-07-05 07:15:49

问题


Pyjnius allows you to create a python wrapper for java classes like:

Hardware = autoclass('org.myapp.Hardware')

Is there a way to import an existing *.jar file like that? What does the syntax look like?


回答1:


You can add the jar into CLASSPATH, then import pyjnius and use autoclass as normal :-):

import os
os.environ['CLASSPATH'] = "path/to/your.jar"

from jnius import autoclass


Bla = autoclass('bla.bla.BlaClass')



回答2:


As much as jar file relevant only for android, you need to add jar file in your buildozer.spec like

android.add_jars = java/myjar.jar

and in your App's build method

from kivy.utils import platform
...
if platform() == 'android':
    BlaClass = autoclass('java.bla.BlaClass')
...


来源:https://stackoverflow.com/questions/21506319/pyjnius-import-jar-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!