在JS脚本

时间:2017-05-12 08:52:11

标签: javascript java nashorn resemblejs

如何在我的JS脚本中导入resemblejs模块?

我的脚本包含类似 -

的功能
    function compareImages(picture1,picture2)
    {
         var diff =resemble(picture1).compareTo(picture2).ignoreColors().onComplete(function(data)
          {
               //console.log(data);  
          });
    return data;
   }

'返回数据'是这样我可以使用scriptengine在我的java程序中调用这个函数,并在java控制台中显示'data'(参见上面代码中的console.log(data))。

    Object res = inv.invokeFunction("compareImages", <path of image1>, <path 
                                  of image2>);
    System.out.println(res);

1 个答案:

答案 0 :(得分:0)

Nashorn有自己的load( js )方法。 您可以使用它来导入模块

示例:

  

script1.js

function say(thing){
    print(thing);
}
  

script2.js

load("./script1.js");
say("Hi");

这应该打印你好

相关问题