1

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?

1

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

2 Comments

So are you saying that it's possible that a library might not be Jython-compatible?
Yes. I've edited my answer to provide a link to the Jython/CPython compatibility info
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.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.