简体   繁体   English

Java包装器到Perl / Python代码

[英]Java Wrapper to Perl/Python code

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. 我必须在仅支持Java的服务器上部署一些Web服务,但其中一些将使用perl或python完成。 I want to know if is possible to develop a Java wrapper to call a specific code written in perl or python. 我想知道是否可以开发一个Java包装器来调用用perl或python编写的特定代码。 So, I want to have all the Web Services in Java, but some of them will call some code using other languages. 所以,我希望用Java编写所有Web服务,但其中一些将使用其他语言调用一些代码。

Thanks in advance. 提前致谢。 Regards, Ukrania 此致,乌克兰

For the Python part of it you can use Jython to run Python code right from your Java virtual machine. 对于它的Python部分,您可以使用Jython直接从Java虚拟机运行Python代码。 It'll integrate fully with your Java code as a bonus. 它将与您的Java代码完全集成,作为奖励。

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. 如果Jython是Python代码的一个选项(它并不总是100%兼容),那么它可能是最好的选择。 Otherwise, you will need to use Java's Process Builder to call the interpretters directly and return the results on their output stream. 否则,您将需要使用Java的Process Builder直接调用解释器并在其输出流上返回结果。 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. 这不会很快(但是,相对于常规Java代码,Jython也不是那么快),但它是一个非常灵活的解决方案。

For Perl, use Inline::Java . 对于Perl,使用Inline :: Java There are several options for integrating the code; 集成代码有几种选择; you can call a separate process or you can use an embedded interpreter . 您可以调用单独的进程 ,也可以使用嵌入式解释器

For Python you can use the Java Scripting API . 对于Python,您可以使用Java Scripting API
A Perl implementation is sadly still missing. 遗憾的是,Perl实现仍然缺失。

There's something I used a while back called Jython which allows you to execute Python code from Java. 我曾经使用过一些名为Jython的东西,允许你从Java执行Python代码。 It was a little quirky, but I got it to do what I needed. 这有点古怪,但我得到它做我需要的。

http://www.jython.org http://www.jython.org

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM