Java 包装到 Perl/Python 代码

问题描述:

我必须在仅支持 Java 服务的服务器上部署一些 Web 服务,但其中一些将使用 perl 或 python 完成.我想知道是否可以开发一个 Java 包装器来调用用 perl 或 python 编写的特定代码.所以,我想拥有 Java 中的所有 Web 服务,但其中一些会使用其他语言调用一些代码.

I have to deploy some Web Services on a server that only supports the Java ones, but some of them will be done using perl or python. I want to know if is possible to develop a Java wrapper to call a specific code written in perl or python. So, I want to have all the Web Services in Java, but some of them will call some code using other languages.

提前致谢.问候,乌克兰

Thanks in advance. Regards, Ukrania

这在很大程度上取决于您的需求.如果 Jython 是 Python 代码的一个选项(它并不总是 100% 兼容),那么它可能是那里的最佳选择.否则,您将需要使用 Java 的 Process Builder 直接调用解释器并在其输出流中返回结果.这不会很快(但话说回来,相对于常规 Java 代码,Jython 也没有那么快),但它是一个非常灵活的解决方案.

This depends heavily upon your needs. If Jython is an option for the Python code (it isn't always 100% compatible), then it is probably the best option there. Otherwise, you will need to use Java's Process Builder to call the interpretters directly and return the results on their output stream. This will not be fast (but then again, Jython isn't that fast either, relative to regular Java code), but it is an extremely flexible solution.