scriptengine

Java ScriptEngine supported languages

杀马特。学长 韩版系。学妹 提交于 2021-02-07 04:52:50
问题 Java has a ScriptEngine system that allows you to run/evaluate statements in a different language. I know for a fact that JavaScript is supported, but I couldn't find any other languages to work with it. Is, for example, Ruby implemented? 回答1: ..I know for a fact that JavaScript is supported,.. ECMAscript, technically. .. but I couldn't find any other languages to work with it. Is, for example, Ruby implemented? No. The ECMAscript engine is the only one included by default, the last time I

Java ScriptEngine supported languages

依然范特西╮ 提交于 2021-02-07 04:52:02
问题 Java has a ScriptEngine system that allows you to run/evaluate statements in a different language. I know for a fact that JavaScript is supported, but I couldn't find any other languages to work with it. Is, for example, Ruby implemented? 回答1: ..I know for a fact that JavaScript is supported,.. ECMAscript, technically. .. but I couldn't find any other languages to work with it. Is, for example, Ruby implemented? No. The ECMAscript engine is the only one included by default, the last time I

How to run UglifyJS2 without Node.JS

安稳与你 提交于 2020-02-21 13:00:08
问题 Anyway to run UglifyJS2 without node.js? Say I would like to run it in a JVM process using JavaScript script engine. How to do that? 回答1: I saw mishoo answered you https://github.com/mishoo/UglifyJS2/issues/122 Two possible ways: run uglifyjs --self to get a build of UglifyJS that you can load in a browser (or in any JS environment) and you can use the API described here. load in your environment all files in the lib/ directory (load utils.js and ast.js first, the others can come in whatever

How to convert type Object from engine.eval to type int

巧了我就是萌 提交于 2020-01-15 23:04:47
问题 My program takes a String input and calculates it using engine.eval() from ScriptEngine imports. How do I convert the evaluated value to type int? import javax.script.ScriptEngine; import javax.script.ScriptEngineManager; import javax.script.ScriptException; public class Main { public static void main(String[] args) { String s = "206 + 4"; Object eval; ScriptEngineManager mgr = new ScriptEngineManager(); ScriptEngine eng = mgr.getEngineByName("JavaScript"); try { eval = eng.eval(s); } catch

How do you invoke a method in a Nashorn CompiledScript?

旧巷老猫 提交于 2020-01-05 17:18:44
问题 I have the following code which works: ScriptEngine jsEngine = ScriptEngineManager.new().getEngineByName("nashorn"); jsEngine.eval("some script"); jsEngine.invokeMethod(jsEngine.eval("foo"), "bar"); but I want to do use a pre-compiled script so I don't have to evaluate the script every time I need to run it, so I'm trying; ScriptEngine jsEngine = ScriptEngineManager.new().getEngineByName("nashorn"); CompiledScript compiledJS = jsEngine.compile("some script"); but then I'm not sure what to do

Java ScriptEngine (nashorn & rhino) : how to stack scopes / bindings?

放肆的年华 提交于 2020-01-04 17:54:47
问题 I have to port a software using Rhino1.7R4 and its org.mozilla.javascript package to use the javax.script package and its ScriptEngine ( Rhino in Java 6 & 7, Nashorn in Java 8). The main problem is to stack scopes (Bindings). Using the Rhino jar, I do: Scriptable scope ... Scriptable newScope = javascriptContext.initStandardObjects(); newScope.setParentScope(scope); So if a variable is defined without var, it's a global variable (root scope) if a variable is defined with var, it's a local

Using Rhino instead of ScriptEngine to run Javascript code in Java

牧云@^-^@ 提交于 2019-12-30 17:22:30
问题 Based on the discussion converting string representation of unknown date-format to Date in java, I want to use the JavaScript Date function in my App-Engine project. However, ScriptEngine does not work on App-Engine. So I need a little help converting to Rhino. Here is the ScriptEngine code I need to convert: ScriptEngineManager scriptEngineManager = new ScriptEngineManager(); ScriptEngine engine = scriptEngineManager.getEngineByName("JavaScript"); String script = "var date = new Date('" +

With Java ScriptEngine (Groovy), how to make it more performant?

青春壹個敷衍的年華 提交于 2019-12-30 00:38:52
问题 I am using ScriptEngine in my app to evaluate some client code in my application. The problem is it's not performant enough and I need to take measures to improve the time of execution. Currently, it can take up to 1463ms (average is around 300ms) to eval an extremely simple script which is basically parameter replacement in URLs. I'm looking for simple strategies to improve this performance without losing the scripting ability. My first thought it to pool the ScriptEngine object and reuse it

With Java ScriptEngine (Groovy), how to make it more performant?

拈花ヽ惹草 提交于 2019-12-30 00:38:12
问题 I am using ScriptEngine in my app to evaluate some client code in my application. The problem is it's not performant enough and I need to take measures to improve the time of execution. Currently, it can take up to 1463ms (average is around 300ms) to eval an extremely simple script which is basically parameter replacement in URLs. I'm looking for simple strategies to improve this performance without losing the scripting ability. My first thought it to pool the ScriptEngine object and reuse it

Evaluating a string holding a logic operation as a Boolean in java

白昼怎懂夜的黑 提交于 2019-12-25 09:17:36
问题 I am trying to evaluate "in1 && in2" to a Boolean as a test, but i hope to be able to evaluate all booleans as stings for my actual project. in1 and in2 are the names of nodes that have a boolean state, i get the actual expression like so, logic = logic.replaceAll(curName, (nodes.get(ins.get(j)).getState() ? "true" : "false")); logic is the string contacting the logic i want evaluated, curname is the current node name being replaced with its boolean("in1" for example) its in a loop so all