简体   繁体   中英

Cannot resolve method 'resolvePythonScriptPath'

I'm following this tutorial about integrating Java and Python .

And I keep getting Cannot resolve method 'resolvePythonScriptPath' in 'TestIntegration' what import am I missing for this method resolvePythonScriptPath() ?

This is my code:

import org.junit.Test;
import javax.script.ScriptContext;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.SimpleScriptContext;
import java.io.FileReader;
import java.io.StringWriter;

import static org.junit.Assert.*;

public class TestIntegration {
    @Test
    public void givenPythonScriptEngineIsAvailable_whenScriptInvoked_thenOutputDisplayed() throws Exception {
        StringWriter writer = new StringWriter();
        ScriptContext context = new SimpleScriptContext();
        context.setWriter(writer);

        ScriptEngineManager manager = new ScriptEngineManager();
        ScriptEngine engine = manager.getEngineByName("python");
        engine.eval(new FileReader(resolvePythonScriptPath("hello.py")), context);
        assertEquals("Should contain script output: ", "Hello Baeldung Readers!!", writer.toString().trim());
    }
}

You should write your own method. it could be something like:

private String resolvePythonScriptPath(String path){
   File file = new File(path);
   return file.getAbsolutePath();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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