Questions tagged [jsr223]

JSR223 (Scripting for the Java Platform) is the Java Specification Request for a common scripting engine abstraction layer.

JSR223 (Scripting for the Java Platform) is the Java Specification Request for a common scripting engine abstraction layer.

As an example (from the Java Scripting Programmer's Guide):

import javax.script.*;
public class EvalScript {
    public static void main(String[] args) throws Exception {
        // create a script engine manager
        ScriptEngineManager factory = new ScriptEngineManager();
        // create a JavaScript engine
        ScriptEngine engine = factory.getEngineByName("JavaScript");
        // evaluate JavaScript code from String
        engine.eval("print('Hello, World')");
    }
}

The interface to instantiate a scripting engine and evaluate a script is language-agnostic; "JavaScript" could be changed to "Python" to evaluate in Python (via Jython) rather than JavaScript (via Rhino).

343 questions
53
votes
4 answers

Should I use a separate ScriptEngine and CompiledScript instances per each thread?

My program uses Java Scripting API and can eval some scripts concurrently. They don't use shared script objects, Bindings or Context, but can use same ScriptEngine and CompiledScript objects. I see that Oracle Nashorn implementation in Java 8 is not…
And390
  • 1,410
  • 2
  • 15
  • 20
40
votes
4 answers

Where can I find a list of available JSR-223 scripting languages?

I need a JVM-based scripting language for my app and would like to see what else is out there besides Groovy, Ruby, and Python. Google keeps pointing me to a dead page at http://scripting.dev.java.net/
HDave
  • 20,105
  • 26
  • 133
  • 216
21
votes
5 answers

Message is not printing on the console in jmeter using JSR223 and groovy

println() inside static void main method is not printing anything anywhere, whereas only println() prints in terminal. Here is my code: class CalcMain { static void main(def args) throws Exception { ScriptEngineManager factory = new…
Pratik
  • 840
  • 2
  • 13
  • 30
18
votes
5 answers

How to convert Rhino-JavaScript arrays to Java-Arrays

I have the following: ScriptEngineManager mgr = new ScriptEngineManager(); ScriptEngine jsEngine = mgr.getEngineByName("JavaScript"); jsEngine.eval("function getArray() {return [1,2,3,4,5];};"); Object result = jsEngine.eval("getArray();"); How can…
Chris
  • 14,451
  • 18
  • 70
  • 73
14
votes
3 answers

Sandboxing JSR-223

I'm trying to sandbox JSR-223. Specifically, I don't want any script to have access to any of my classes. (I hear Rhino can do that with ClassShutter, but I want to do it generally. ie. for all script engines of JSR-223). I first tried to use the…
David
14
votes
1 answer

What JVM-based scripting language support @WebService to create services at runtime?

I am at a situation where I need to be able to create and expose a webservice at run time. (i.e. no "javac"-compilation step). Is there a JVM-based scripting language that has good support for JAX-WS so I can write a central engine in Java, and…
Thorbjørn Ravn Andersen
  • 68,906
  • 28
  • 171
  • 323
10
votes
3 answers

Java Scripting With Nashorn (JSR 223) & Pre-compilation

I am using Nashorn via JSR 223 to execute small snippets of user entered script: public Invocable buildInvocable(String script) throws ScriptException { ScriptEngine engine = new ScriptEngineManager().getEngineByName(ENGINE); …
Kong
  • 7,648
  • 14
  • 58
  • 89
9
votes
3 answers

Is OSGi fundamentally incompatible with JSR-223 Scripting Language Discovery?

I've recently written a small specialist scripting language and used the Maven to export an OSGi compliant bundle that also exports a service descriptor into the "META-INF/services/javax.script.ScriptEngineFactory" service registry file. The problem…
Chris
  • 4,200
  • 3
  • 35
  • 46
9
votes
1 answer

Is Groovy ScriptingEngine thread safe?

When you call : Object isThreadSafe = scriptEngine.getFactory().getParameter("THREADING"); It returns MULTITHREADED as per: https://docs.oracle.com/javase/8/docs/api/javax/script/ScriptEngineFactory.html#getParameter-java.lang.String- But it…
UBIK LOAD PACK
  • 31,356
  • 4
  • 58
  • 100
9
votes
1 answer

How much memory does a Nashorn ScriptEngine use?

We are currently in the process of adding a server-side scripting capability to one of our products. As part of this I am evaluating JSR 223 script engines. As we may potentially be running large numbers of scripts on the server, I am particularly…
Neil Madden
  • 518
  • 4
  • 12
8
votes
4 answers

Replace in Java Rhino (JSR223) with actual file name

In my code, all of the scripts are contained in .js files. Whenever one of the scripts contains an error, I get this: javax.script.ScriptException: sun.org.mozilla.javascript.internal.EcmaError: ReferenceError: "nonexistant" is not defined.…
TheLQ
  • 14,081
  • 11
  • 66
  • 104
7
votes
1 answer

How to access Java exception that causes ScriptException using JSR-223

I'm executing Javascripts using the JSR-223 script engine built into JRE6. The Javascripts are able to access Java code and objects. When an exception is thrown from the Java code that is executed from a JavaScript, the ScriptEngine will throw a…
Dave H
  • 537
  • 1
  • 4
  • 15
7
votes
3 answers

How do I set up jsr223 scripting with scala as scripting language

So far I have tried the sling implementation for jsr223 scripting for scala, but was not able to get it set up correctly. when I do this: public static void main(String[] args) { try { new…
VivaceVivo
  • 71
  • 1
  • 2
7
votes
1 answer

reasonable handling of ScriptException thrown by JSR223 Rhino

I'm starting to run into the dirty little secrets of what is an otherwise very useful JSR223 scripting environment. I'm using the builtin version of Rhino shipped with Java 6 SE, accessing it through JSR223's ScriptingEngine et al. When I get an…
Jason S
  • 171,795
  • 155
  • 551
  • 900
6
votes
2 answers

Running kotlin through JSR-223 is incredibly slow

I'm running the following code and it's taking between 3 and 6 seconds to execute on both OSX (Sierra) and Windows 10. I've never seen such slowness using JSR-223, especially considering the simplicity of what's being evaluated. Digging through…
L Morris
  • 201
  • 1
  • 2
  • 5
1
2 3
22 23