JPype这玩意可以桥接Java,在Python中调用Java的类,比较好用,对外接口不多,不过需要注意的是python和java类型匹配的问题.可以参考官方文档
http://jpype.sourceforge.net/doc/user-guide/userguide.html
过程中遇到个小问题,设置classpath时,-D前面留了一个空格,导致始终找不到类的错误,很坑爹。
jvmArg = "-Djava.class.path=%s" % ext_classpath
jpype.startJVM(jvmpath,jvmArg)
JPype defines different leels of "match" between Python objects and Java types. These levels are :
-
none, There is no way to convert.
-
explicit (E), JPype canconvert ot the desired type, but only explicitly via the wrapper classes. This means the proper wrapper class will access this type as argument.
-
implicit (I), JPype will convert as needed.
-
exact> (X), Like implicit, but when deciding with method overload to use, one wj=here all the paramters match "exact" will take precedence over "implicit" matches.
byte
short
int
long
float
double
boolean
char
String
Array
Object
Class
int
I (1)
|
I (1)
|
X
|
I
|
|
|
X (10)
|
|
|
|
|
|
long
I (1)
|
I (1)
|
I (1)
|
X
|
|
|
|
|
|
|
|
|
float
|
|
|
|
I (1)
|
X
|
|
|
|
|
|
|
sequence
|
|
|
|
|
|
|
|
|
|
|
|
dictionary
|
|
|
|
|
|
|
|
|
|
|
|
string
|
|
|
|
|
|
|
I (2)
|
X
|
|
|
|
unicode
|
|
|
|
|
|
|
I (2)
|
X
|
|
|
|
JByte
X
|
|
|
|
|
|
|
|
|
|
|
|
JShort
|
X
|
|
|
|
|
|
|
|
|
|
|
JInt
|
|
X
|
|
|
|
|
|
|
|
|
|
JLong
|
|
|
X
|
|
|
|
|
|
|
|
|
JFloat
|
|
|
|
X
|
|
|
|
|
|
|
|
JDouble
|
|
|
|
|
X
|
|
|
|
|
|
|
JBoolean
|
|
|
|
|
|
X
|
|
|
|
|
|
JString
|
|
|
|
|
|
|
|
X
|
|
I (3)
|
|
JChar
|
|
|
|
|
|
|
X
|
|
|
|
|
JArray
|
|
|
|
|
|
|
|
|
I/X (4)
|
I (5)
|
|
JObject
|
|
|
|
|
|
|
|
|
I/X (6)
|
I/X (7)
|
|
JavaObject
|
|
|
|
|
|
|
|
|
|
I (8)
|
|
JavaClass
|
|
|
|
|
|
|
|
|
|
I (9)
|
X
|
(1) Conversion will occur if the Python value fits in the java native type.
(2) Conversion occurs if the python string or unicode is of length 1
(3) The required object must be of a type compatible with java.lang.String (java.lang.Object,
java.util.Comparable)
(4) Number of dimensions must match, and the types must be compatible
(5) Only when the required type is java.lang.Object
(6) Only if the JObject wrapper's specified type is an compatible array class.
(7) Only if the required type is compatible with the wrappers's specified type. The actual type of the java object is not considered.
(8) Only if the requireds type is compatible with the Java Object actual type.
(9) Only when the required type is java.lang.Object or
java.lang.Class
(10) only the values True and False are implitly converted to booleans.
Converting from java to python
The rules here are much simpler.
Java byte, short and int are converted to python int.
Java long are conversion to Python long
Java float and double are converted to python float.
Java boolean are converted to python int of value 1 or 0
Java char are converted to python unicode of length 1.
Java String are converteds to python unicode.
Java arrays are converteds to JArray
All other java object are converted to JavaObject.
Java Class are converted to JavaClass.
Java array Class are converted to JavaArrayClass.
分享到:
相关推荐
python桥接程序,可以把你的单个网卡桥接多个虚拟路由器
python代码转java工具,没有用过不知行不行,如果你试用了评论一下告诉后来人。
java2python--java代码转python工具
python 利用 jpype 调用java代码
资源分类:Python库 所属语言:Python 资源全名:JPype1-1.3.0-cp37-cp37m-win_amd64.whl 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
Python 调用Java实例详解 前言: Python 对服务器端编程不如Java 所以这方面可能要调用Java代码 前提: Linux 环境 1 安装 jpype1 安装后测试代码: from jpype import * startJVM(getDefaultJVMPath(), "-ea...
设计模式专题之(十)桥接模式---设计模式桥接模式示例代码(python--c++)
支持2.7,大家可以下。下了很久了
桥接模式 Bridge:将抽象部分与他的实现部分分离,使他们都可以独立的变化合成/聚合复用原则: 尽量使用合成/聚合,尽量不要使用继承解释:什么叫抽象与他的实现分离,并不是说,让抽象类与其派生类分离,因为这就没有任何...
python 调用java代码方法
python 实现 桥接模式
Python兼容Java bouncycastle包的国密sm2加解密方法
C、Python、Java输出每个月的天数函数解析 C、Python、Java输出每个月的天数函数解析 C、Python、Java输出每个月的天数函数解析 C、Python、Java输出每个月的天数函数解析 C、Python、Java输出每个月的天数函数解析 ...
本脚本用python实现java项目的一键发布,装好python环境、paramiko模块修改自己的服务器账号密码,项目地址等即可完成一键发布上传实现。有日志输出。
JPype最新版,使用于py2.7,主要用于phthon调用JAVA
各种学习资料 Android Python Java Java web C语言 C++ 汇编 Android逆向 Arm开发 51单片机 Photoshop 会声会影 Windows Unity cocos2dx 教程 视频 各种学习资料 Android Python Java Java web C语言 C++ 汇编 ...
主要用于手动安装python3.6.1对应的jpype1 库。使用pip install wheel 安装wheel成功后,再次安装该文件 pip install ****.whl 即可。
steam热销游戏信息抓取,基于node.js , python , java分别实现.zip steam热销游戏信息抓取,基于node.js , python , java分别实现.zip steam热销游戏信息抓取,基于node.js , python , java分别实现.zip steam热销...