Question

Does anyone know any Java ScriptEngine that understand/include implicit DOM objects like window, document, self etc? I can't use JavaFX WebEngine as I am not developing JavaFX application.

Was it helpful?

Solution 3

One of solutions is using Envjs. Follow this example how to embed into Java application. Now I can use document.title, document.getElementById('embed_rhino_dojo_shell').innerHTML etc.

import org.mozilla.javascript.Context;
import org.mozilla.javascript.ContextFactory;
import org.mozilla.javascript.tools.shell.Global;
import org.mozilla.javascript.tools.shell.Main;
...
Context cx = ContextFactory.getGlobal().enterContext();
cx.setOptimizationLevel(-1);
cx.setLanguageVersion(Context.VERSION_1_5);
Global global = Main.getGlobal();
global.init(cx);
Main.processSource(cx, "path/to/your/JSfile");
cx.evaluateString(...);

OTHER TIPS

Not Perfectly answering your question

But We have used Qt's WebView which gives browser like functionality . It is same as JavaFX WebEngine . And PhoneGap also gives webview for mobile devices .

So please Clarify properly about in which situation you want to add Script Engine ?

see link for basic informations related to Qt http://www.slideshare.net/QT-day/qt-webkit

There is no way to have that. DOM variables like 'window' and 'document' in a JVM don't make sense.

The Java ScriptEngine was made so you can 'script' the logic that you would normally perform in plain java.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top