Java Python 集成 [英] Java Python Integration
问题描述
我有一个需要与第 3 方库集成的 Java 应用程序.该库是用 Python 编写的,我对此没有任何发言权.我试图找出与它集成的最佳方式.我正在尝试 JEPP(Java Embedded Python)——以前有人用过吗?我的另一个想法是使用 JNI 与 Python 的 C 绑定进行通信.
I have a Java app that needs to integrate with a 3rd party library. The library is written in Python, and I don't have any say over that. I'm trying to figure out the best way to integrate with it. I'm trying out JEPP (Java Embedded Python) - has anyone used that before? My other thought is to use JNI to communicate with the C bindings for Python.
任何有关执行此操作的最佳方法的想法将不胜感激.谢谢.
Any thoughts on the best way to do this would be appreciated. Thanks.
推荐答案
为什么不使用 Jython?我能立即想到的唯一缺点是您的库是否使用 CPython 本机扩展.
Why not use Jython? The only downside I can immediately think of is if your library uses CPython native extensions.
如果您现在可以使用 Jython ,但认为您在使用更高版本的库时可能会遇到问题,我建议您尝试将库与您的应用程序隔离(例如某种适配器接口).使用目前最简单的方法,然后在需要时考虑 JNI/CPython/etc.除非您真的必须这样做,否则走(痛苦的)JNI 路线几乎没有什么好处.
If you can use Jython now but think you may have problems with a later version of the library, I suggest you try to isolate the library from your app (e.g. some sort of adapter interface). Go with the simplest thing that works for the moment, then consider JNI/CPython/etc if and when you ever need to. There's little to be gained by going the (painful) JNI route unless you really have to.
这篇关于Java Python 集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!