Classpath resources with Nashorn (JJS)

657 Views Asked by At

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.

0

There are 0 best solutions below