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

查看:140
本文介绍了从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
a用于从C ++ / Python $ b调用Java的C ++代码生成器$ b但这需要编译每个可能的呼叫;我更喜欢另一种解决方案。

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-and-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?

还有其他选择吗?

问候,
David

Regards, David

推荐答案

以下是我对此问题的总结:5种从Python调用Java的方法

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 / cached

简短回答: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天全站免登陆