Hello. Please tell me: how can I execute a script located on a remote site in a java application? I tried to use ScriptEngineManager, but for some reason he doesn’t want to work at all. Set a task to write your own browser. But I just can not figure out the scripts. Initially, the site scripts are downloaded to the folder. But when they start to run, a bunch of errors crashes. For example, that there is no window variable, but after all, window is not a variable? Or am I misunderstanding something?
public void scriptExecutor(){ try{ File file = new File("/Users/user/desktop/js"); File[] f = file.listFiles(); ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("nashorn"); for(int i = 0; i<f.length; i++){ System.out.println(f[i]); engine.eval(Files.newBufferedReader(Paths.get(f[i].getAbsolutePath()))); } }catch(Exception e){e.printStackTrace();} }
windowis an object representing a browser window. When the script is executed in a Java application, there is no browser, therefore nowindow. - user194374