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?
Asked
Active
Viewed 441 times
3 Answers
4
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
- 268,207
- 37
- 334
- 440
-
So are you saying that it's possible that a library might not be Jython-compatible? – jjujuma Jun 05 '09 at 09:13
-
Yes. I've edited my answer to provide a link to the Jython/CPython compatibility info – Brian Agnew Jun 05 '09 at 09:15
2
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
- 2,371
- 5
- 19
- 27
0
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
- 74,053
- 25
- 135
- 175