Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

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.

share|improve this question
    
Try changing your jython-standalone dependency version to 2.7.1b2. – Ravikumar 17 hours ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.