在脚本中包含 Rhino shell 方法或加载其他 js 脚本的简单方法?

发布于 2024-10-19 03:16:24 字数 397 浏览 4 评论 0原文

我正在尝试使用Rhino shell方法,例如加载、打印等。我的问题与这个,但是,我不能在不破解的情况下访问实际的java代码框架本身(accela Automation FWIW)。我希望能够轻松添加其他 .js 脚本,例如 jQuery。但需要注意的是,我只能访问 javascript 脚本 - 而不能访问实际的 java 上下文。话虽这么说,我(当然)可以做典型的 Rhino 事情,例如调用 java 类、对象等。

有没有人做过这个,或者有什么好主意,我将如何去做?

I'm trying to use the Rhino shell methods such as load, print, etc. My question is SIMILAR to this one, however, I DO NOT have access to the actual java code without hacking apart the framework itself (accela automation FWIW). I'd like to be able to easily add on other .js scripts such as jQuery. But the big caveat is that I only have access to the javascript scripts - not the actual java context. That being said - I can (of course) do the typical Rhino things such as call on java classes, objects, etc.

Has anyone done this or have any good ideas how I would go about it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

﹏半生如梦愿梦如真 2024-10-26 03:16:24

看来这就是我一直在寻找的:

var manager = new Packages.javax.script.ScriptEngineManager();
var engine = manager.getEngineByName( "js" );

var scriptFile = "/pathToScript/scriptFileName.js";
var eval = engine.eval( new Packages.java.io.FileReader( new Packages.java.io.File( " + scriptFile + " ) ) );

Seems this is what I was looking for:

var manager = new Packages.javax.script.ScriptEngineManager();
var engine = manager.getEngineByName( "js" );

var scriptFile = "/pathToScript/scriptFileName.js";
var eval = engine.eval( new Packages.java.io.FileReader( new Packages.java.io.File( " + scriptFile + " ) ) );
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文