国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

腳本之家,腳本語言編程技術(shù)及教程分享平臺(tái)!
分類導(dǎo)航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服務(wù)器之家 - 腳本之家 - Python - Python基于pyjnius庫實(shí)現(xiàn)訪問java類

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

2020-08-01 00:02Tracydzf Python

這篇文章主要介紹了Python基于pyjnius庫實(shí)現(xiàn)訪問java類,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下

簡(jiǎn)介

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

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

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

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

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

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

安裝

先安裝Java JDK 和JRE、Cython

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#
pip3 install cython
# pip3 install jniusx
Collecting jniusx
Downloading jniusx - 1.0.5. tar.gz
Requirement already satisfied: six >=
    1.7.0 in /opt/python
3.5 / lib / python3.5 / site - packages(
    from jniusx)
Requirement already satisfied: cython in
    /opt/python
3.5 / lib / python3.5 / site - packages(
    from jniusx)
Installing collected packages: jniusx
Running setup.py install
for jniusx...done
Successfully installed jniusx - 1.0.5

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

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

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 需要利用原來保存的clone。

快速入門

hello world 實(shí)例:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#!/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 demo
Tested in python2.7
    ""
"
from jnius
import autoclass
System = autoclass('java.lang.System')
System.out.println('Hello World')

堆棧實(shí)例:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/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 demo
Tested in python2.7
    ""
"
from jnius
import autoclass
Stack = 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

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#!/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 hashCode
Tested in python2.7
    ""
"
from jnius
import autoclass
String = autoclass('java.lang.String')
print(String("hello").hashCode())

調(diào)用jar包

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!python
 
#
vi com / sample / Beach.java
package 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è)試:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!python
 
#
ipython
Python 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 jnius
import autoclass
In[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 jnius
import autoclass
AESUtil = autoclass(
    'com.oppo.sso.util.AESUtil')
email = AESUtil.aesEncrypt(
    "hello@126.com", "我是一個(gè)加密密鑰")
print(email)# !python
# ipython
Python 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 jnius
import autoclass
In[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 jnius
import autoclass
AESUtil = autoclass(
    'com.oppo.sso.util.AESUtil')
email = AESUtil.aesEncrypt(
    "hello@126.com", "我是一個(gè)加密密鑰")
print(email)

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持服務(wù)器之家。

原文鏈接:https://www.cnblogs.com/tracydzf/p/13387900.html

延伸 · 閱讀

精彩推薦
Weibo Article 1 Weibo Article 2 Weibo Article 3 Weibo Article 4 Weibo Article 5 Weibo Article 6 Weibo Article 7 Weibo Article 8 Weibo Article 9 Weibo Article 10 Weibo Article 11 Weibo Article 12 Weibo Article 13 Weibo Article 14 Weibo Article 15 Weibo Article 16 Weibo Article 17 Weibo Article 18 Weibo Article 19 Weibo Article 20 Weibo Article 21 Weibo Article 22 Weibo Article 23 Weibo Article 24 Weibo Article 25 Weibo Article 26 Weibo Article 27 Weibo Article 28 Weibo Article 29 Weibo Article 30 Weibo Article 31 Weibo Article 32 Weibo Article 33 Weibo Article 34 Weibo Article 35 Weibo Article 36 Weibo Article 37 Weibo Article 38 Weibo Article 39 Weibo Article 40
主站蜘蛛池模板: 日韩福利视频 | 成人激情视频免费在线观看 | 99精品欧美一区二区三区综合在线 | 午夜精品视频在线观看 | 婷婷91| 在线视频自拍 | 视频一区在线 | 欧美一区二区免费 | 亚洲国产精品一区二区久久 | 日韩高清中文字幕 | 视频在线一区二区 | 99在线精品视频 | av在线一区二区 | 黄色毛片网站在线观看 | 一本大道香蕉大a√在线 | 久久久久高清 | 精品国产一区二区三区性色av | 红杏首页| 欧美精品v国产精品v日韩精品 | 日韩6699人妻熟女毛片 | 午夜视频免费 | 成人av电影网 | 久久国产视频精品 | 国产一区二区日韩 | 久久精品久久久久电影 | 亚洲欧美视频 | 国产亚洲精品久久久久久 | jav久久亚洲欧美精品 | 国产精品69毛片高清亚洲 | 怡红院在线播放 | 我和我的祖国电影在线观看免费版高清 | 免费视频一区二区 | 免费黄色观看 | 色一色网站 | av色伊人久久综合一区二区 | 欧美一区亚洲二区 | 国产一区二区欧美 | 久久综合一区二区 | 精品第一页| 欧美一级视频在线观看 | 国产欧美日韩综合精品一区二区 |