Shvalb
Shvalb

Reputation: 1933

Java8, Nashorn: failed to load external .js script file

I'm brand new to Nashorn and trying to load my first js file as follow:

public static void main(String[] args) {
        final ScriptEngineManager manager = new ScriptEngineManager();
        final ScriptEngine engine = manager.getEngineByName("nashorn");

        try {   
            engine.eval("load('https://cdn.jsdelivr.net/sockjs/1.0.3/sockjs.min.js')");

        }catch(final ScriptException e) {
            System.err.println(e);
        }

    }

I get the following Exception:

javax.script.ScriptException: TypeError: Cannot read property "prototype" from undefined in http://cdn.jsdelivr.net/sockjs/1.0.3/sockjs.min.js at line number 3

in addition, when I try to evaluate the following:

engine.eval("load('https://code.jquery.com/jquery-1.11.3.min.js')");

the eval() method doesn't return at all - it just stuck on debug (Using Eclipse).

Any idea why prototype isn't defined, any why I cannot evaluate jquery js file?

Thanks!

Upvotes: 0

Views: 1911

Answers (1)

Mike Shauneu
Mike Shauneu

Reputation: 3289

Nashorn is a ECMAScript5 compatible JavaScript engine. WebSocket API is not a part of ECMAScript 5 but browser API. That's because you get exception.

Upvotes: 1

Related Questions