从 Python 调用 Java [英] Calling Java from Python

查看:30
本文介绍了从 Python 调用 Java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从python调用java的最佳方法是什么?(jython 和 RPC 不适合我).

What is the best way to call java from python? (jython and RPC are not an option for me).

我听说过 JCC:http://pypi.python.org/pypi/JCC/1.9用于从 C++/Python 调用 Java 的 C++ 代码生成器但这需要编译每一个可能的调用;我更喜欢另一种解决方案.

I've heard of JCC: http://pypi.python.org/pypi/JCC/1.9 a C++ code generator for calling Java from C++/Python But this requires compiling every possible call; I would prefer another solution.

我听说过 JPype:http://jpype.sourceforge.net/教程:http://www.slideshare.net/onyame/mixing-python-和-java

I've hear about JPype: http://jpype.sourceforge.net/ tutorial: http://www.slideshare.net/onyame/mixing-python-and-java

import jpype 
jpype.startJVM(path to jvm.dll, "-ea") 
javaPackage = jpype.JPackage("JavaPackageName") 
javaClass = javaPackage.JavaClassName 
javaObject = javaClass() 
javaObject.JavaMethodName() 
jpype.shutdownJVM() 

这看起来正是我需要的.但是,最后一个版本是 2009 年 1 月发布的,我看到有人无法编译 JPype.

This looks like what I need. However, the last release is from Jan 2009 and I see people failing to compile JPype.

JPype 是一个死项目吗?

Is JPype a dead project?

还有其他选择吗?

推荐答案

这里是我对这个问题的总结:5 Ways of Calling Java from Python

Here is my summary of this problem: 5 Ways of Calling Java from Python

http://baojie.org/blog/2014/06/16/call-java-from-python/(缓存)

简短回答:Jpype 运行良好,并在许多项目中得到证明(例如 python-boilerpipe),但 Pyjnius 比 JPype 更快、更简单

Short answer: Jpype works pretty well and is proven in many projects (such as python-boilerpipe), but Pyjnius is faster and simpler than JPype

我尝试过 Pyjnius/Jnius、JCC、javabridge、Jpype 和 Py4j.

I have tried Pyjnius/Jnius, JCC, javabridge, Jpype and Py4j.

Py4j 有点难用,因为你需要启动一个网关,又增加了一层脆弱性.

Py4j is a bit hard to use, as you need to start a gateway, adding another layer of fragility.

这篇关于从 Python 调用 Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆