2

有人对如何开始使用 Oracle 的新 JS 引擎 Nashorn 有任何指示吗?

我已经安装了 JDK 8 b80,但仍然只有 Rhino:

@Test
public void list() {
   ScriptEngineManager manager = new ScriptEngineManager();
   List<ScriptEngineFactory> factories = manager.getEngineFactories();
   for (ScriptEngineFactory factory : factories) {
       System.out.println(factory.getEngineName());
   }
}

输出:

"C:\Program Files\Java\jdk1.8.0\bin\java" -ea -Didea.launcher.port=7537...
Mozilla Rhino
4

2 回答 2

1

Install the JDK8 and create an alias for your JDK's jjs (Nashorn Interpreter), e.g., if you create a file called test.js, you can run the program with:

$ jjs test.js

Mac OS = alias jjs=’/Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/jre/bin/jjs’</p>

Windows = Define an environment variable called ‘JAVA8_HOME’ and point to your jdk8 folder, then you can invoke jjs by running this command:

“%JAVA8_HOME%\jre\bin\jjs” test.js

Here's an example of a Nashorn App: http://marcelorjava.wordpress.com/2013/08/24/code-walkthrough-online-kanban-board-with-nashorn/

于 2013-08-26T15:12:00.973 回答
1

抱歉,我也不喜欢别名的东西,所以正如 wickund 建议的那样,我会简短地说(并且还使用了 hohonuuli 发布的技巧)

cd /usr/bin; ln -s $(/usr/libexec/java_home -v 1.8)/bin/jjs jjs

以root身份执行,否则由于缺少权限,您将不会幸运

于 2014-09-29T19:57:34.423 回答