我有示例 python 文件,我需要通过 java 程序调用它。因为这是我正在使用的Jython
.
Pom 依赖
<dependency>
<groupId>org.python</groupId>
<artifactId>jython-standalone</artifactId>
<version>2.7.0</version>
</dependency>
Java 文件
公共类 JythonIntegrationTest {
public static void main(String[] args) throws FileNotFoundException , ScriptException {
StringWriter writer = new StringWriter();
ScriptEngineManager manager = new ScriptEngineManager();
ScriptContext context = new SimpleScriptContext();
context.setWriter(writer);
ScriptEngine engine = manager.getEngineByName("python");
engine.eval(new FileReader("D:\\python\\sample.py") , context);
System.out.println(writer.toString());
}
}
当我运行这个程序时,我得到以下错误:-
线是 -manager.getEngineByName("python");
Exception in thread "main" java.lang.NullPointerException
at maven_test.maven_test.JythonIntegrationTest.main(JythonIntegrationTest.java:38)
我需要在系统上运行一些 python exe/服务吗?