久久福利_99r_国产日韩在线视频_直接看av的网站_中文欧美日韩_久久一

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

Python基于pyjnius庫(kù)實(shí)現(xiàn)訪問(wèn)java類

瀏覽:27日期:2022-07-15 15:58:26

簡(jiǎn)介

Pyjnius是一個(gè)用于訪問(wèn)Java類的Python庫(kù)。

適用場(chǎng)景:極個(gè)別的加密算法等內(nèi)容,用python不方便實(shí)現(xiàn)或者實(shí)現(xiàn)較耗時(shí),可基于Pyjnius把java類當(dāng)做python庫(kù)使用。

文檔:http://pyjnius.readthedocs.io/en/latest/installation.html

下載地址:https://pypi.python.org/pypi?%3Aaction=search&term=jnius&submit=search

注意jnius的版本管理有點(diǎn)混亂,目前看來(lái)選擇jniusx比較好。

git地址:https://github.com/kivy/pyjnius/blob/master/docs/source/index.rst

安裝

先安裝Java JDK 和JRE、Cython

#pip3 install cython# pip3 install jniusxCollecting jniusxDownloading jniusx - 1.0.5. tar.gzRequirement already satisfied: six >=1.7.0 in /opt/python3.5 / lib / python3.5 / site - packages(from jniusx)Requirement already satisfied: cython in/opt/python3.5 / lib / python3.5 / site - packages(from jniusx)Installing collected packages: jniusxRunning setup.py installfor jniusx...doneSuccessfully installed jniusx - 1.0.5

注意:jnius安裝的坑比較多,請(qǐng)參考http://stackoverflow.com/search?q=jnius

如果出現(xiàn)ImportError,一般是java環(huán)境變量或者path沒(méi)有配置好。

jnius/jnius.c:4:20: fatal error: Python.h 一般為缺python-dev, yum -y install python-devel

pip 安裝不成功可以嘗試 setup.py方式。

jnius/jnius.c: No such file or directory 需要利用原來(lái)保存的clone。

快速入門

hello world 實(shí)例:

#!/usr/bin/env python#- * -coding: utf - 8 - * -#jnius_quick2.py# Author Rongzhong Xu 2016 - 08 - 02 wechat:pythontesting# https: //bitbucket.org/china-testing/python-chinese-library/src'''jnius demoTested in python2.7'''from jniusimport autoclassSystem = autoclass(’java.lang.System’)System.out.println(’Hello World’)

堆棧實(shí)例:

#!/usr/bin/env python#- * -coding: utf - 8 - * -#jnius_quick1.py# Author Rongzhong Xu 2016 - 08 - 02 wechat:pythontesting# https: //bitbucket.org/china-testing/python-chinese-library/src'''jnius demoTested in python2.7'''from jniusimport autoclassStack = autoclass(’java.util.Stack’)stack = Stack()stack.push(’hello’)stack.push(’world’)print(stack.pop())# -- > ’world’print(stack.pop())# -- > ’hello’

調(diào)用java String的hashCode

#!/usr/bin/env python#- * -coding: utf - 8 - * -#jnius_quick3.py# Author Rongzhong Xu 2016 - 08 - 02 wechat:pythontesting# https: //bitbucket.org/china-testing/python-chinese-library/src'''jnius demo: Call java String ’s hashCodeTested in python2.7'''from jniusimport autoclassString = autoclass(’java.lang.String’)print(String('hello').hashCode())

調(diào)用jar包

#!python#vi com / sample / Beach.javapackage com.sample;public class Beach {private String name;private String city;public Beach(String name, String city) {this.name = name;this.city = city;}public String getName() {return name;}public void setName(String name) {this.name = name;}public String getCity() {return city;}public void setCity(String city) {this.city = city;}}#echo Main - Class: Beach > manifest.txt# jar cvfm Test.jar manifest.txt com /sample /*.class*/

測(cè)試:

#!python#ipythonPython 3.5.2(default, Nov 7 2016, 18: 53: 51)Type 'copyright', 'credits'or 'license'for more information.IPython 5.1.0--An enhanced Interactive Python.? - > Introduction and overview of IPython’s features.% quickref - > Quick reference.help - > Python ’s own help system.object ? - > Details about ’object’,use ’object??’for extra details.In[2]: #注意要先把jar加載CLASSPATH環(huán)境變量。In[3]: from jniusimport autoclassIn[4]: Bla = autoclass(’com.sample.Beach’)In[5]: s = Bla('Tom', 'Shenzhen')In[6]: s.getName()Out[6]: ’Tom’```封裝某模塊的加密機(jī)制為python包實(shí)例:* 拷貝: com cn org 到新建的臨時(shí)目錄* echo Main-Class: AESUtil >manifest.txt* jar cvfm Test.jar manifest.txt *測(cè)試代碼:```python# - * -coding: utf - 8 - * -#注意要先把jar加載CLASSPATH環(huán)境變量。from jniusimport autoclassAESUtil = autoclass(’com.oppo.sso.util.AESUtil’)email = AESUtil.aesEncrypt('hello@126.com', '我是一個(gè)加密密鑰')print(email)# !python# ipythonPython 3.5.2(default, Nov 7 2016, 18: 53: 51)Type 'copyright', 'credits'or 'license'for more information.IPython 5.1.0--An enhanced Interactive Python.? - > Introduction and overview of IPython’s features.% quickref - > Quick reference.help - > Python ’s own help system.object ? - > Details about ’object’,use ’object??’for extra details.In[2]: #注意要先把jar加載CLASSPATH環(huán)境變量。In[3]: from jniusimport autoclassIn[4]: Bla = autoclass(’com.sample.Beach’)In[5]: s = Bla('Tom', 'Shenzhen')In[6]: s.getName()Out[6]: ’Tom’```封裝某模塊的加密機(jī)制為python包實(shí)例:* 拷貝: com cn org 到新建的臨時(shí)目錄* echo Main-Class: AESUtil >manifest.txt* jar cvfm Test.jar manifest.txt *測(cè)試代碼:```python# - * -coding: utf - 8 - * -#注意要先把jar加載CLASSPATH環(huán)境變量。from jniusimport autoclassAESUtil = autoclass(’com.oppo.sso.util.AESUtil’)email = AESUtil.aesEncrypt('hello@126.com', '我是一個(gè)加密密鑰')print(email)

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。

標(biāo)簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 欧美激情视频一区二区三区在线播放 | 成人资源在线观看 | 亚洲视频观看 | 欧美日韩高清 | 亚洲综合视频 | 草草视频在线播放 | 日韩二区三区 | 国产欧美精品一区二区三区四区 | 国产成人99久久亚洲综合精品 | av大片 | 一区二区毛片 | 国产高清在线观看 | 国产一区二区三区在线看 | 狠狠亚洲| 欧美午夜精品久久久 | 精品免费视频 | 99精品国产高清一区二区麻豆 | 色吧综合网| 精品国产18久久久久久二百 | 欧美午夜精品久久久 | 午夜男人网 | 日本免费黄色 | 国产精品久久久久久久久久久久午夜片 | 激情综合久久 | 91精品久久久久久久久 | 最近最新中文字幕 | jlzzjlzz亚洲日本少妇 | 亚洲一区二区三区免费视频 | 亚洲视频一区二区三区 | 在线婷婷 | 国产精品成人国产乱一区 | 日韩高清不卡一区二区三区 | jizzjizz亚洲中国少妇 | 成人a在线视频免费观看 | 国产一二三区在线观看 | 日日摸天天做天天添天天欢 | 亚洲狠狠 | 中文字幕成人 | 日韩久久影院 | 欧美日本韩国一区二区 | 黄色综合网 |