> On Jul 19, 2017, at 4:01 PM, Daniel Manresa Menargues <
ilde...@gmail.com> wrote:
>
> I need to use rhino for load and run scripts from java.
>
> I have the rhino dependency on my pom, but when i run the application, i obtain a null when i try to load rhino.
>
> My code:
>
> ScriptEngineManager scriptManager = new ScriptEngineManager();
>
> ScriptEngine jsEngine = scriptManager.getEngineByExtension("rhino"); //jsEngine is null after this.
>
> if (jsEngine==null) {
> jsEngine = scriptManager.getEngineByExtension("js");
> }
>
> If i print all the "EngineFactories" availables i only obtain this:
>
>
> ScriptEngineFactory Info
> Script Engine: Oracle Nashorn (1.8.0_91)
Nashorn replaced Rhino as the JDK provided JSR 223, IIRC, JavaScript interface didn’t it?
>
> Anybody knows how to load rhino in Java?
Provide your own Rhino interface. My Java shell program, currently known as HalfPipe (a platform for skateboarding tricks),
did this.
engines
ScriptEngineManager providers.next(): javax.script.ScriptEngineFactory: Provider us.hall.scripting.RhinoScriptEngineFactory could not be instantiated
ScriptEngineFactory Info
Factory class:class org.codehaus.groovy.jsr223.GroovyScriptEngineFactory
Script Engine: Groovy Scripting Engine (2.0)
Engine Alias: groovy
Engine Alias: Groovy
Language: Groovy (2.4.5)
ScriptEngineFactory Info
Factory class:class org.rosuda.jrs.RScriptFactory
Script Engine: REngine (0.7)
Engine Alias: REngine
Language: R (2)
ScriptEngineFactory Info
Factory class:class apple.applescript.AppleScriptEngineFactory
Script Engine: AppleScriptEngine (1.1)
Engine Alias: AppleScriptEngine
Engine Alias: AppleScript
Engine Alias: OSA
Language: AppleScript (2.5)
ScriptEngineFactory Info
Factory class:class jdk.nashorn.api.scripting.NashornScriptEngineFactory
Script Engine: Oracle Nashorn (1.8.0_131)
Engine Alias: nashorn
Engine Alias: Nashorn
Engine Alias: js
Engine Alias: JS
Engine Alias: JavaScript
Engine Alias: javascript
Engine Alias: ECMAScript
Engine Alias: ecmascript
Language: ECMAScript (ECMA - 262 Edition 5.1)
Although you can see it is currently broken. This is because I added a global scope function to the interface that allowed it to pid attach to any OS X java process and script it with JavaScript.
This was based on code in tools.jar. I somewhat recently decided to eliminate the tools.jar dependency and broke it.
I roughly plan on getting it working for Java 9 again at some point when that eliminates tools.jar altogether, my understanding.
But anyhow, it would definitely be possibly for you to provide your own interface without that dependency.