import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import java.io.FileReader;
public class Main {
public static void main(String[] args
In javascript window means browser window. So when you are trying to execute this js from Java, it is unable to find browser window and you are getting error. You can use URL class in Java to get the content of the url.