Java Wrapper to Perl/Python code
Asked Answered
P

5

4

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

Pizarro answered 29/7, 2009 at 16:53 Comment(1)
Generating a .class file from the perl/python script is also a solution, because I can deploy the web service using only the .class file.Pizarro
S
4

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.

Simpleton answered 29/7, 2009 at 17:6 Comment(2)
I have to support python completely, I just want to call or use the code that other programmers had made, in the easiest way possible. In the end, I have to publish this features using web services, that need to be made on java because WSO2 only supports Java Web Services (I use WSO2 to make the Web Services secure).Pizarro
Yes, I think writing scripts to call the interpretter using ProcessBuilder is going to be the most compatible choice.Simpleton
P
3

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.

Pyrrhuloxia answered 29/7, 2009 at 16:56 Comment(2)
I will have a Python program ready to the final release, using Jython it will call the functions that are already written or I need to rewrite the code?Pizarro
Yes you should be able to call existing Python functions. Jython can run almost any Python code but not all Python standard modules are available in Jython. I believe this is particularly likely if the modules are written in C.Pyrrhuloxia
C
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.

Cortese answered 29/7, 2009 at 23:9 Comment(1)
yes but this solution is to call Java code inside Perl, I want to call Perl code from JavaPizarro
C
1

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

Cental answered 29/7, 2009 at 17:5 Comment(0)
E
0

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

Eremite answered 29/7, 2009 at 16:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.