Basically I need to use one library written in javascript for my java application, and I am shaking my head on how to do it. Here is the library: https://github.com/mikeemoo/jsgo. For now I am trying to get the examples working (to no avail). It says that require
is not defined. As far as require('jsgo') goes, I can just shove my script into the library and I am good with it. However, I don't know how to resolve require('fs'), which is needed to read from file. This is how I launch the script:
package csgodemo;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
public class DemoMain {
public static void main (String[] args) throws NoSuchMethodException, IOException, InterruptedException, ScriptException{
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("js");
try {
FileReader reader = new FileReader("./script.js");
engine.eval(reader);
reader.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}