Java Wrapper to Perl/Python code

拜拜、爱过 提交于 2019-12-23 20:11:31

问题


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


回答1:


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.




回答2:


For the Python part of it you can use Jython to run Python code right from your Java virtual machine. It'll integrate fully with your Java code as a bonus.




回答3:


For Perl, use Inline::Java. There are several options for integrating the code; you can call a separate process or you can use an embedded interpreter.




回答4:


For Python you can use the Java Scripting API.
A Perl implementation is sadly still missing.




回答5:


There's something I used a while back called Jython which allows you to execute Python code from Java. It was a little quirky, but I got it to do what I needed.

http://www.jython.org



来源:https://stackoverflow.com/questions/1201628/java-wrapper-to-perl-python-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!