Search code examples
javajavascriptjava-8nashorn

Java8 Nashorn - ReferenceError: "eu" is not defined


I'm trying to call a static method on a class from JavaScript executed by Nashorn:

var hooks = new JavaImporter(eu.wansdyke.carbon.hooks);
with (hooks) {
  Archiver.archive(bucket, key, existingValue, 1);
}

Unfortunately I'm getting this error:

javax.script.ScriptException: ReferenceError: "eu" is not defined in  at line number 2

The class that invokes Nashorn is in a eu.wansdyke... package so I'm a bit surprised at this. Is there something I'm doing wrong?


Solution

  • If you access it through the Packages object, I think it will work.

    For instance:

    Packages.eu.wansdyke.carbon.hooks
    

    For referenced pull it from the : Nashorn Docs