I am writing a JavaScript program in Rhino which needs to load other JavaScript files. However the built-in load()
function loads files relatively to the current directory and I need to load them relatively to the location of the script (so that the program can be called form any directory).
In other languages I would use something like dirname(__FILE__) + "/path/file"
, but it seems that Rhino does not have __FILE__
or anything similar. I have tried to extract the current file from a thrown exception, but it is empty, i.e. the following code prints "true":
try {
throw new Error();
} catch (e) {
print(e.fileName === "");
}
I tried to look at the interpreter sources and use the Java-JavaScript bridge, but I didn't find anything helpful yet (I'll probably look more).
Does anybody have a tip how to make loading files on relative paths work?