与java集成 [英] Integration with java

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

问题描述

您好,


我正在使用Python开发一个项目,而且我现在正在讨论


用Java编写一些

项目模块的可能性。鉴于

的很大一部分代码已经用Python编写,使用

标准库和几个扩展模块,我

am

试图通过Jython衡量与

Java

集成的可行性,对现有代码影响最小,



未来代码的复杂性,以及截止日期!


我一般都需要知道它有多脏〜

将这两种语言结合起来,以及我需要考虑的成本是多少。我还有兴趣知道是否

有任何普遍接受的策略来完全支持
切换项目语言(我考虑,在

极端情况下,将它全部改为Java),如果用/或
用Java编写一些模块并替换其余的模块逐渐变得有意义。

我想到的三个更具体的问题:

1.是否可以以类似于
py2exe的方式打包Jython / Java程序?是否有可能以这样的方式打包Python,Jython和Java代码?

2.在大量数据结构之间传输

Java和Jython运行的Python代码对内存有显着的影响吗?例如,

将大型数据库查询的结果从

Java

传递给Jython,以便进一步处理,导致整个

要复制的数据或类似的东西?

3.我是否遗漏了任何有趣的东西?


谢谢!


Joe。

__________________________________________________

你是否雅虎!?

厌倦了垃圾邮件?雅虎邮件具有最好的垃圾邮件保护
http://mail.yahoo.com

Hello,

I am working on a project in Python, and I"m
currently
looking into the possibiliy of writing some of the
project"s modules in Java. Given that a large part of
the code is already written in Python, using the
standard libraries and several extension modules, I
am
trying to gauge the viability of integration with
Java
via Jython with minimal impact on present code, on
the
complexity of future code, and on deadlines!

I need to know in general how dirty it will be to
combine the two languages, and what the costs I
should
take into account are. I"m also interested to know if
there are any commonly accepted strategies to fully
switch project languages (I"m considering, in the
extreme case, to change it all into Java), and if
writing some modules in Java and replacing the rest
gradually makes sense.

Three more specific questions I thought of:
1. Is is possible to pack a Jython/Java program in a
py2exe-like fashion? Is it possible to pack in such a
way both Python, Jython and Java code?
2. Does transferring large data structures between
Java and Python code running by Jython have a
significant effect on memory? For example, would
passing the result of a large database query from
Java
to Jython, for further processing, cause the entire
data to be duplicated or something similar?
3. Did I miss anything fundemental?

Thanks!

Joe.
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

推荐答案

Joachim Boomberschloss写道:
Joachim Boomberschloss wrote:
代码已经用Python编写,使用
标准库和几个扩展模块
the code is already written in Python, using the
standard libraries and several extension modules




要记住的一件事是Jython没有整合CPython,而是了解 ; python代码

直接。所以,如果你有一个与python一起使用的C扩展

它不能与Jython一起工作。


我的感觉是,如果你有很多编写的Java代码和

想要在python上建立Jython将是一个更好的

适合,反之亦然。


Istvan 。



One thing to keep in mind is that Jython does not
integrate CPython, instead it "understands" python code
directly. So if you have a C extension that works with python
it won''t work with Jython.

My feeling is that if you had a lot of Java code written and
wanted to build on that with python Jython would be a better
fit than vice versa.

Istvan.


使用JNI调用来自

CPython的java模块是可能的,尽管可能很痛苦。这比Jython集成更难,但如果你想继续使用你的扩展模块,可能需要




JNI教程可以在
http://java.sun.com /docs/books/tutor...1.1/index.html


我可能不会采用这种方法,除非java提供了一些

令人难以置信的实质性好处,或者我正在使用复杂的java系统集成复杂的python

系统。我也可以从

开始创建一个好的C API来通过JNI访问所需的java模块,然后使用SWIG( http://www.swig.org/ )生成python包装器。


当然,如果您可以删除已经编写的扩展模块,那么从Jython访问Java只是一个导入语句。

祝你好运,


克里斯

It is possible, though possibly painful, to call java modules from
CPython using JNI. This is more difficult than Jython integration, but
probably required if you want to keep using your extension modules.

The JNI tutorial is available at
http://java.sun.com/docs/books/tutor...1.1/index.html .

I probably would not take this approach unless java offered some
incredibly substantial benefit or I was integrating a complex python
system with a complex java sytem. I would also probably start by
creating a good C API to access the required java modules via JNI and
then use SWIG (http://www.swig.org/) to generate the python wrapper.

Of course if you can drop the extension modules you have already
written, accessing Java from Jython is just an import statement away.
Good luck,

Chris


这个怎么样?
http://jpype.sourceforge.net/


(我自己也没用过)

How about this?
http://jpype.sourceforge.net/

(I haven''t used it myself)


这篇关于与java集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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