我有示例python文件,我需要通过java程序调用 . 因为这是使用 Jython .

Pom Dependency

<dependency>
    <groupId>org.python</groupId>
    <artifactId>jython-standalone</artifactId>
    <version>2.7.0</version>
</dependency>

Java File

公共类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 / service .