Thread: RhinoScripting with Jre8

Results 1 to 2 of 2
  1. #1 RhinoScripting with Jre8 
    Registered Member Andrew's Avatar
    Join Date
    Nov 2008
    Posts
    2,890
    Thanks given
    612
    Thanks received
    207
    Rep Power
    551
    Well since it is was change or removed or whatever; what do I change it to now?

    my scriptmanager class goes as follow:

    Code:
    package org.rs2server.rs2;
    
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.InputStreamReader;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    
    import javax.script.Invocable;
    import javax.script.ScriptEngine;
    import javax.script.ScriptEngineManager;
    import javax.script.ScriptException;
    
    import com.sun.script.javascript.RhinoScriptEngine;
    
    /**
     * Manages server scripts.
     * @author blakeman8192
     * 
     */
    public class ScriptManager {
    	
    	/**
    	 * The singleton of this class.
    	 */
    	private static final ScriptManager INSTANCE = new ScriptManager();
    	
    	/**
    	 * Gets the ScriptManager singleton.
    	 * @return The ScriptManager singleton.
    	 */
    	public static ScriptManager getScriptManager() {
    		return INSTANCE;
    	}
    
    	/**
    	 * The ScriptEngineManager.
    	 */
    	@SuppressWarnings("unused")
    	private ScriptEngineManager mgr;
    
    	/**
    	 * The JavaScript Engine.
    	 */
    	private ScriptEngine jsEngine;
    
    	/**
    	 * The logger for this manager.
    	 */
    	private final Logger logger = Logger.getLogger(this.toString());
    
    	/**
    	 * Creates the script manager.
    	 */
    	private ScriptManager() {
    		mgr = new ScriptEngineManager();
    		jsEngine = new RhinoScriptEngine();
    		logger.info("Loading scripts...");
    	}
    
    	/**
    	 * Invokes a JavaScript function.
    	 * @param identifier The identifier of the function.
    	 * @param args The function arguments.
    	 * @return if the script was found
    	 */
    	public boolean invokeWithFailTest(String identifier, Object... args) {
    		Invocable invEngine = (Invocable) jsEngine;
    		try {
    			invEngine.invokeFunction(identifier, args);
    			return true;
    		} catch (NoSuchMethodException ex) {
    			return false;
    		} catch (ScriptException ex) {
    			logger.log(Level.WARNING, "ScriptException thrown!", ex);
    			return false;
    		}
    	}
    
    	/**
    	 * Invokes a JavaScript function.
    	 * @param identifier The identifier of the function.
    	 * @param args The function arguments.
    	 */
    	public void invoke(String identifier, Object... args) {
    		Invocable invEngine = (Invocable) jsEngine;
    		try {
    			invEngine.invokeFunction(identifier, args);
    		} catch (NoSuchMethodException ex) {
    			logger.log(Level.WARNING, "No such method: " + identifier, ex);
    		} catch (ScriptException ex) {
    			logger.log(Level.WARNING, "ScriptException thrown!", ex);
    		}
    	}
    
    	/**
    	 * Loads JavaScript files into the JavaScript ScriptEngine from the argued
    	 * path.
    	 * @param dirPath The path of the directory to load the JavaScript source files
    	 * from.
    	 */
    	public void loadScripts(String dirPath) {
    		File dir = new File(dirPath);
    		if (dir.exists() && dir.isDirectory()) {
    			File[] children = dir.listFiles();
    			for (File child : children) {
    				if (child.isFile() && child.getName().endsWith(".js"))
    					try {
    						jsEngine.eval(new InputStreamReader(
    								new FileInputStream(child)));
    					} catch (ScriptException ex) {
    						logger.log(Level.SEVERE, "Unable to load script!", ex);
    					} catch (FileNotFoundException ex) {
    						logger.log(Level.SEVERE, "Unable to find script!", ex);
    					}
    				else if (child.isDirectory())
    					loadScripts(child.getPath());
    			}
    		}
    	}
    
    }
    what's highlighted in red are where the errors are, i have no idea what to do so just a little guidance would be great ;D
    Reply With Quote  
     

  2. #2  
    Respected Member


    Join Date
    Jan 2009
    Posts
    5,743
    Thanks given
    1,162
    Thanks received
    3,603
    Rep Power
    5000
    like i said in the shoutbox andrew in java 8 rhino was replaced with nashorn to fix your class replace


    Code:
    jsEngine  = new RhinoScriptEngine();
    to
    Code:
    jsEngine = mgr.getEngineByName("JavaScript");
    and then delete the rhino import.

    that will now use the default engine available to your java install be it rhino or nashorn
    Reply With Quote  
     

  3. Thankful user:



Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Latest Endar with cache
    By sarah101 in forum Downloads
    Replies: 29
    Last Post: 04-15-2010, 04:29 AM
  2. [tut]Poison Npcs (With green splat)..
    By Santa Clause in forum Tutorials
    Replies: 9
    Last Post: 05-21-2007, 03:55 AM
  3. Buddy guy with attack skillcape..
    By System.Out in forum Showcase
    Replies: 10
    Last Post: 04-19-2007, 05:55 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •