2

I've noticed that, when using nashorn's command line utility JJS, any resource that is included in the classpath, be it included in a JAR or located in a classpath folder, is not available to scripts. A simple example:

echo "java.lang.Class.class.getResourceAsStream('/test.txt')" | jjs -cp .

When a file "test.txt" is included in the current folder (which is added to the classpath via the -cp option), this code always returns "null". If I run a similar example using java and the jvm directly I get the expected resource (an input stream reference). Under rhino I get the same results, using a similar example.

Is this the expected behavior? Is there a way to access resources under the classpath in nashorn? This is causing a lot of problems with spring contexts for example, everytime I try to load my app context from an XML file I get problems because it cannot find some needed resources at runtime. This worked fine under rhino, but we are planning on migrating to nashorn. Any help is greatly appreciated.

emerino
  • 1,100
  • 11
  • 17
  • I found this github wiki, were it states loading resources is only possible for nashorn's app class loader: https://github.com/DaniHaag/snippets/wiki/Nashorn – emerino Sep 25 '16 at 23:15
  • This related question is given a useful answer, but it involves creating the nashorn engine programatically, instead of using JJS: http://stackoverflow.com/questions/30225398/java-8-scriptengine-across-classloaders – emerino Sep 25 '16 at 23:17

0 Answers0