Python桥接Java工具JPype
来源:互联网 发布:hm淘宝官网旗舰店 编辑:程序博客网 时间:2024/05/16 07:39
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.
(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桥接Java工具JPype
- jpype python 调用java
- Java to Python integration--JPype
- Jpype python 调用JAVA 类
- python调用java程序--jpype
- 使用python调用java-jpype
- [转]python调用Java-JPype使用介绍
- python调用Java-JPype使用介绍
- Python+Jpype 调用 Java 碰壁全记录
- JPype:实现在python中调用JAVA
- python调用Java-JPype使用介绍
- python调用Java-JPype使用介绍
- Python 通过Jpype调用Java类
- JPype:实现在python中调用JAVA
- python使用JPype来运行java文件
- JPype:实现在python中调用JAVA
- python 使用 jpype 调用java类
- JPype:实现在python中调用JAVA
- Eclipse无法启动:Failed to create the Java Virtual Machine
- js 动态时间特效
- 存储的开始
- 高通MSM8255串口驱动移植
- windows7菜单不消失的问题
- Python桥接Java工具JPype
- aspx页面输出xml格式
- ARM-Linux s3c2440 之中断分析(三)
- badVersion For ClassFile
- 直接调用类成员函数地址
- Flex 容器阴影
- C#调用API函数给Winform窗体添加动态特效
- 学习微软 Script技术的重要资源
- acm生涯结束记