欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

 更新時間:2020年07月31日 14:31:39   作者:Tracydzf  
這篇文章主要介紹了Python基于pyjnius庫實現(xiàn)訪問java類,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下

簡介

Pyjnius是一個用于訪問Java類的Python庫。

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

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

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

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

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

安裝

先安裝Java JDK 和JRE、Cython

#
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安裝的坑比較多,請參考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 實例:

#!/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')

堆棧實例:

#!/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'

調用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 hashCode
Tested in python2.7
	""
"
from jnius
import autoclass
String = autoclass('java.lang.String')
print(String("hello").hashCode())

調用jar包

#!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*/

測試:

#!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'
``
`

封裝某模塊的加密機制為python包實例:

* 拷貝: com cn org 到新建的臨時目錄

* echo Main-Class: AESUtil >manifest.txt

* jar cvfm Test.jar manifest.txt *

測試代碼:

`
``
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", "我是一個加密密鑰")
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'
``
`

封裝某模塊的加密機制為python包實例:

* 拷貝: com cn org 到新建的臨時目錄

* echo Main-Class: AESUtil >manifest.txt

* jar cvfm Test.jar manifest.txt *

測試代碼:

`
``
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", "我是一個加密密鑰")
print(email)

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

  • Python3安裝模塊報錯Microsoft Visual C++ 14.0 is required的解決方法

    Python3安裝模塊報錯Microsoft Visual C++ 14.0 is required的解決方法

    這篇文章主要介紹了Python3安裝模塊報錯Microsoft Visual C++ 14.0 is required的解決方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2020-07-07
  • Flask路由尾部有沒有斜杠有什么區(qū)別

    Flask路由尾部有沒有斜杠有什么區(qū)別

    這篇文章主要介紹了Flask路由尾部加不加斜杠有什么區(qū)別,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2022-09-09
  • Python數(shù)據分析之?Matplotlib?折線圖繪制

    Python數(shù)據分析之?Matplotlib?折線圖繪制

    這篇文章主要介紹了Python數(shù)據分析之?Matplotlib?折線圖繪制,在數(shù)據分析中,數(shù)據可視化也非常重要,下文通過數(shù)據分析展開對折線圖的繪制,需要的小伙伴可以參考一下
    2022-05-05
  • Python文件處理

    Python文件處理

    這篇文章主要介紹了Python文件處理的相關資料,需要的朋友可以參考下
    2016-02-02
  • python基于C/S模式實現(xiàn)聊天室功能

    python基于C/S模式實現(xiàn)聊天室功能

    這篇文章主要為大家詳細介紹了python基于C/S模式實現(xiàn)聊天室功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-01-01
  • 一文帶你了解Python與svg之間的操作

    一文帶你了解Python與svg之間的操作

    svgwrite是一個?Python?庫,用于生成簡單的?SVG?圖片。它提供了一組類似于繪圖的?API,使用者可以在?SVG?畫布上畫線、矩形、圓等圖形。本文主要介紹了如何利用svgwrite進行SVG圖片的操作,需要的可以參考一下
    2023-01-01
  • Python Tkinter Menu控件使用詳解

    Python Tkinter Menu控件使用詳解

    Menu控件(菜單控件)可以說是 GUI 中“精髓所在”,它以可視化的方式將一系列的命令進行分組,在每一個分組下又可以“隱藏”許多的程序執(zhí)行命令(即功能)。本文將詳細介紹它的使用,需要的可以參考一下
    2022-01-01
  • Python實現(xiàn)簡單登錄驗證

    Python實現(xiàn)簡單登錄驗證

    這篇文章主要為大家詳細介紹了Python實現(xiàn)簡單登錄驗證的相關資料,需要的朋友可以參考下
    2016-04-04
  • pytorch實現(xiàn)查看當前學習率

    pytorch實現(xiàn)查看當前學習率

    這篇文章主要介紹了pytorch實現(xiàn)查看當前學習率,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-06-06
  • Python導入其他文件夾中函數(shù)的實現(xiàn)方法

    Python導入其他文件夾中函數(shù)的實現(xiàn)方法

    本文主要介紹了Python導入其他文件夾中函數(shù)的實現(xiàn)方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2023-01-01

最新評論