Search code examples
javajavascriptrhino

How to not import system lib classes in java rhino lib script?


I use java Rhino lib as a script engine in my application, so that users can write their own script to control the application to do some job,

but I don't want them to use the java system lib classes in script ,ex:"java.lang.Sytem.exit()",

does anyone know how to do?? thank you


Solution

  • Call Context.setClassShutter(ClassShutter) on your context with an appropriate ClassShutter implementation that implements the method visibleToScripts(String fullClassName) in whatever way you wish to filter out (or in) whatever classes you want to have be usable from the scripts.