admin管理员组

文章数量:1391969

ScriptEngine engine = new ScriptEngineManager().getEngineByName("JavaScript");

engine is null??? Also i try to iterate through the scriptEnginefactories it's zero...

i have js-1.7R1.jar on my classpath...can anyone tell me what i need to do else to register the javascript engine( I found Rhino which is js-1.7r.jar)

Thanks.

ScriptEngine engine = new ScriptEngineManager().getEngineByName("JavaScript");

engine is null??? Also i try to iterate through the scriptEnginefactories it's zero...

i have js-1.7R1.jar on my classpath...can anyone tell me what i need to do else to register the javascript engine( I found Rhino which is js-1.7r.jar)

Thanks.

Share Improve this question asked Oct 5, 2012 at 19:53 Jeryl CookJeryl Cook 1,03819 silver badges42 bronze badges 4
  • How are you running the class? Through an IDE? If so, is its piler-level set to Java 1.6 or higher? – Bart Kiers Commented Oct 5, 2012 at 19:58
  • Eclipse uses its own piler, but uses the system's JRE: you sure your JRE is 1.6+? Do other 1.6 features work? (annotations) – Bart Kiers Commented Oct 5, 2012 at 20:39
  • @BartKiers Thanks! your ments help point me in right direction..in my IDE i had to remove my JRE(it was 1.5) and add it back as 1.6....i recently changed to 1.6 but did not fix that...... thanks , i was stuck for a good while :/ – Jeryl Cook Commented Oct 5, 2012 at 20:48
  • @Jeryl Cook Can you make that solution official and answer your own question then so that your question can help others. – Kyle Bridenstine Commented Jul 7, 2014 at 0:57
Add a ment  | 

3 Answers 3

Reset to default 3

"Eclipse uses its own piler, but uses the system's JRE..." - Bart Kiers

Make sure the JRE is 1.6 or higher. Based on the ments, Jeryl Cook had eclipse set to JRE 1.5. He removed this from inside eclipse and added JRE 1.6 which worked and solved his problem.

I had the same problem with JDK 11. Using JDK 8 solved it.

Make sure you have

sun.mozilla.javascript.internal, .sun.script.javascript;

packages in your classpath.
What you are trying to run is fork version of Rhino within Java SE (Java Scripting Api). It looks like your Java doesn't have it (check above packages). I believe js-1.7R1.jar is original Rhino implementation from mozilla - you can try to run it directly link, not via Java Scripting API.

本文标签: javaScriptEngine is Null for getEngineByName(quotJavaScriptquot)Stack Overflow