Forum Stats

  • 3,757,882 Users
  • 2,251,289 Discussions
  • 7,869,962 Comments

Discussions

Why a java script works fine in rhino engine in java1.6, but not in nashorn script engine in java1.8

Solomon Mohanty
Solomon Mohanty Member Posts: 2
edited Jul 12, 2016 10:04PM in JavaScript - Nashorn

A java script to load java classes from a http server by a custom class loader works fine in jre1.6 with rhino engine. But same script doesn't

work in nashorn engine in jre1.8. Exception thrown is

java.security.AccessControlException: access denied ("java.net.SocketPermission" "172.16.48.100:8443" "connect,resolve"

I tried using below URL to give all permission for java and script code to have all permissions.

https://wiki.openjdk.java.net/display/Nashorn/Nashorn+script+security+permissions

Code is similar to below lines:

"var tmp = UcmdbServiceFactory.initSSL();" +

  "var serviceProvider = UcmdbServiceFactory.getServiceProvider(\"https\",\"172.16.48.100\",8443); " +

  "var clientContext = serviceProvider.createClientContext(\"UCSD\"); " ;

     ScriptEngineManager m = new ScriptEngineManager();

      ScriptEngine engine = m.getEngineByName("nashorn");

  File file = new File(args[0]);

        try {

        //engine.eval(com.cloupia.fw.scripting.Constants.JS_RHINO_COMPAT_SCRIPT);

        URI uri = file.toURI();

        URL url = uri.toURL();

        engine.eval(new URLReader(url));

If anybody has any experience with network class loaders using nashorn script engine, help here.