0

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!

1
  • Use unminified version - that will get you more sensible error location. Also you are trying to load libraries made for browser environment (and possibly Node). I doubt that you will be able to simply load them in vanilla JS engine such as Nashorn or Rhino. Commented Dec 21, 2015 at 14:03

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.