What are the basic nuts and bolts of calling (running? interpreting? what can you do?) Python code from a Java program? Are there many ways to do it?
+4
A:
You can embed Jython within your Java application, rather than spawning off a separate process. Provided your library is compatible with Jython, that would seem the most logical place to start.
Brian Agnew
2009-06-05 09:11:42
So are you saying that it's possible that a library might not be Jython-compatible?
jjujuma
2009-06-05 09:13:58
Yes. I've edited my answer to provide a link to the Jython/CPython compatibility info
Brian Agnew
2009-06-05 09:15:48
+2
A:
Apart from embedding Jython as mentioned by Brian, you have these options as well.
Java 1.6 has inbuilt support for scripting. You can find more info here.
Spring also provides excellent support for scripting. JRuby, Groovy are supported by Spring Scripting. You can find info here.
Sathya
2009-06-05 09:20:03
A:
And if none of the other alternatives mentioned (Jython, Spring) work, you can always run an external CPython interpreter and communicate with the JVM through:
- CORBA
- Sockets
- Pipes
- Temporary files
Also maybe you would take a look at OpenOffice's UNO... I think it could be used outside the suite.
fortran
2009-06-05 09:26:36