I have sample python file, which i need to call through java program.
For this is am using Jython
.
Pom Dependency
<dependency>
<groupId>org.python</groupId>
<artifactId>jython-standalone</artifactId>
<version>2.7.0</version>
</dependency>
Java File
public class 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());
}
}
when i run this program, i get below error :-
line is - manager.getEngineByName("python");
Exception in thread "main" java.lang.NullPointerException
at maven_test.maven_test.JythonIntegrationTest.main(JythonIntegrationTest.java:38)
Do i need to run some python exe/service on system.
2.7.1b2
. – Ravikumar 17 hours ago