Why Java Nashorn __DIR__, __LINE__ and __FILE__ are null?
java, java-8, javascript, nashorn, scriptengine
Solution
I know this is an old question, but as I came up with a simple solution I wanted to share it to help people that face the same issue.
In fact you can easily have `__FILE__`, `__DIR__`, and `__LINE__` working if instead of doing the usual:
engine.eval(new FileReader("path_to_your_js"));
You actually call a small JS code that load your file:
engine.eval("load('path_to_your_js')");
Problem
I am trying to get `__DIR__`, `__LINE__` and `__FILE__` Nashorn globals within JavaScript file which is compiled and evaluated by Java Nashorn Engine (JDK 8). However, all of them return NULL... Are they related to some specific Nashorn configuration or? It doesn't say anything in the documentation about any additional configuration to get them working.