简体   繁体   English

如何将 JyNI 嵌入 jar 中

[英]How to embed JyNI in a jar

I'm developing an application in java, and in this one, I use jython-standalone (Jython for untold reasons, its goal being to ease some scripting within the application).我正在用 Java 开发一个应用程序,在这个应用程序中,我使用jython-standalone (Jython 的原因不详,它的目标是简化应用程序中的一些脚本编写)。

I would like to have access to NumPy, and it seems that JyNI provides such capabilities.我想访问 NumPy,而且JyNI似乎提供了这样的功能。

I found many posts explaining how to start a Jython project using JyNI, but none on how to include the .jar or something in the application so that it is available when needed.我发现很多帖子解释了如何使用 JyNI 启动 Jython 项目,但没有关于如何在应用程序中包含 .jar 或其他内容以便在需要时可用。

As stated on JyNI , java -cp build/JyNI.jar -jar jython.jar does not work.JyNI 所述java -cp build/JyNI.jar -jar jython.jar不起作用。

Is there a way for me to use JyNI when executing some Jython code through a PythonInterpreter ?在通过PythonInterpreter执行一些 Jython 代码时,有没有办法让我使用 JyNI?

You should be able to start the live interpreter by executing the class org.python.util.jython.您应该能够通过执行类 org.python.util.jython 来启动实时解释器。

On Linux, OSX:在 Linux、OSX 上:

java -cp jython.jar:build/JyNI.jar org.python.util.jython

On Windows:在 Windows 上:

java -cp jython.jar;build\JyNI.jar org.python.util.jython

Alternatively, one can use Jython's start script:或者,可以使用 Jython 的启动脚本:

jython -J-cp build/JyNI.jar

This info is taken from https://github.com/Stewori/JyNI#running-jyni , but leaving out the script argument someFile.py.此信息取自https://github.com/Stewori/JyNI#running-jyni ,但省略了脚本参数 someFile.py。

If you want to explicitly leverage the interpreter through Java code, you will surely have some way to launch your overall application.如果您想通过 Java 代码显式地利用解释器,您肯定可以通过某种方式启动整个应用程序。 Make sure to have JyNI.jar and the folder containing its binaries on classpath in that command.确保在该命令的类路径上有 JyNI.jar 和包含其二进制文件的文件夹。 Jython should be running with JyNI support then.那时 Jython 应该在 JyNI 支持下运行。

A side-note: Be sure to use Jython 2.7.1 and NumPy >= 1.12.旁注:请务必使用 Jython 2.7.1 和 NumPy >= 1.12。 Version mismatch of these prerequisites is a common cause of failure.这些先决条件的版本不匹配是失败的常见原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM