如何在Java应用程序中使用Python库?

时间:2023-01-13 21:09:58

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?

调用的基本要点是什么(运行?解释?你能做什么?)来自Java程序的Python代码?有很多方法可以做到吗?

3 个解决方案

#1


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.

您可以在Java应用程序中嵌入Jython,而不是在单独的进程中生成。如果您的库与Jython兼容,那么这似乎是最合乎逻辑的起点。

#2


Apart from embedding Jython as mentioned by Brian, you have these options as well.

除了Brian提到的嵌入Jython之外,你也有这些选项。

Java 1.6 has inbuilt support for scripting. You can find more info here.

Java 1.6内置了脚本支持。你可以在这里找到更多信息。

Spring also provides excellent support for scripting. JRuby, Groovy are supported by Spring Scripting. You can find info here.

Spring还为脚本提供了出色的支持。 Spring脚本支持JRuby,Groovy。你可以在这里找到信息。

#3


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:

如果提到的其他替代方法(Jython,Spring)都不起作用,您可以始终运行外部CPython解释器并通过以下方式与JVM通信:

  • 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.

也许你会看一下OpenOffice的UNO ...我认为它可以在套件之外使用。

#1


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.

您可以在Java应用程序中嵌入Jython,而不是在单独的进程中生成。如果您的库与Jython兼容,那么这似乎是最合乎逻辑的起点。

#2


Apart from embedding Jython as mentioned by Brian, you have these options as well.

除了Brian提到的嵌入Jython之外,你也有这些选项。

Java 1.6 has inbuilt support for scripting. You can find more info here.

Java 1.6内置了脚本支持。你可以在这里找到更多信息。

Spring also provides excellent support for scripting. JRuby, Groovy are supported by Spring Scripting. You can find info here.

Spring还为脚本提供了出色的支持。 Spring脚本支持JRuby,Groovy。你可以在这里找到信息。

#3


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:

如果提到的其他替代方法(Jython,Spring)都不起作用,您可以始终运行外部CPython解释器并通过以下方式与JVM通信:

  • 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.

也许你会看一下OpenOffice的UNO ...我认为它可以在套件之外使用。