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).

434 questions
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
  • 251
  • 1
  • 2
  • 5
5
votes
2 answers

jsr223 + writing a script interpreter

OK. ScriptEngine.eval(String string) evaluates a string in its entirety, and ScriptEngine.eval(Reader reader) evaluates the input from a Reader in its entirety. So if I have a file, I can open a FileInputStream, wrap a Reader around it, and call…
Jason S
  • 184,598
  • 164
  • 608
  • 970
5
votes
1 answer

Kotlin JSR-223 ScriptEngineFactory within the fat jar - Cannot find kotlin compiler jar

I have a fat jar where I'm trying to get the instance of Kotlin's ScriptEngine. For the debugging purposes I'm iterating through available Script Engine Factories and getting the engines. val scriptEngineManager = ScriptEngineManager() for (factory…
David Siro
  • 1,826
  • 14
  • 33
5
votes
1 answer

Java Library to generate JavaScript Code

I need to generate JavaScript (ECMAScript) code from inside a Java program. For that, I am looking for something like JavaPoet, but producing JavaScript as output. I cannot use one of these transpilers that translates another language into…
tquadrat
  • 3,033
  • 1
  • 16
  • 29
5
votes
1 answer

How to use JSR-223 to get Scala interpreter in sbt console?

In the sbt console, sbt version 0.13.5, Scala version 2.11.1, I can get javax.script.ScriptEngine for Scala: scala> val engine = new javax.script.ScriptEngineManager().getEngineByName("scala") engine: javax.script.ScriptEngine =…
Dan Getz
  • 8,774
  • 6
  • 30
  • 64
5
votes
1 answer

Importing Python modules in Jython WITHOUT MODIFICATION

Before someone starts ranting: I have already gone through several similar questions on numerous forums, but they do NOT answer my question effectively. Now to the question: Although Java has always been my preferred language, the last few weeks…
divs1210
  • 690
  • 1
  • 8
  • 16
5
votes
1 answer

How to debug JavaScript code called from Java (via JSR-223)?

I'm developing a java application where some logic is performed via jsr223 (javascript). In java class I forward some java object to javascript (e.g. my domain objects, PreparedStatement for some SQL queries) and then I start compiled javascript…
user1337302
  • 113
  • 8
5
votes
0 answers

Classpath problems with JSR223 scripting in Tomcat

I am trying to understand an issue I'm seeing with JSR223 scripting when running inside Tomcat. I'm using the Java scripting engine, but I believe the problem applies more generally (I've seen a similar problem with the reference JS engine as…
wrussell
  • 51
  • 1
4
votes
1 answer

Jmeter JSR223 Groovy read file line by line and do http POST

I am trying to iterate files in the folder. each file has multiple json strings delimited by newline. Once the json is retrieved, will have to get the specific node of the json and POST it to http server. Initially i thought will use the csv data…
Shivakumar ss
  • 653
  • 7
  • 19
4
votes
2 answers

Migrate Nashorn to GraalVM

I am using Nashorn JS engine from OpenJDK 12. Nashorn seems to be deprecated. I am looking which are the available alternatives. I found GraalVM, but I am not sure if this is the best. How can I execute a GraalVM JavaScript from Java ? Do you have…
DbSchema
  • 413
  • 5
  • 16
4
votes
2 answers

Jmeter how to generate hash sha512

I need to create test in jmeter for many requests and I need to create post request which will contain pass in header and it should be hash sha512 from user + someid + someid. I need to change user in each request so I just add in Header Manager…
vb381
  • 181
  • 1
  • 3
  • 14
4
votes
1 answer

JMeter Assertion Results

I am running JSR223 Assertion where I compare expected response to actual response using groovy. If they are not equal, assertion fails. Here is the code import groovy.json.JsonSlurper; JsonSlurper slurper = new JsonSlurper(); boolean…
Dummy
  • 43
  • 1
  • 3
4
votes
1 answer

how to use jsr 223 preprocessor in jmeter?

Someone please help me how to do scripting using jsr223 preprocessor in Jmeter with some examples. Any best site to get tutorial for the same. Thanks in advance SIJO
sijo
  • 89
  • 1
  • 2
  • 14
4
votes
1 answer

Why doesn't jrunscript honor my classpath?

I'm trying to do some JDBC access from JavaScript using the Rhino included in Java 6. But I cannot make the DriverManager find the Driver I want to use. These two examples should be equivalent: Java: public class DbTest { public static void…
clacke
  • 7,688
  • 6
  • 46
  • 48
4
votes
2 answers

JSR223 Postprocessor to parse json in jmeter

I have used BSF Postprocessor to parse json in one of my jmeter test files. My code is as follow. eval('var response = '+prev.getResponseDataAsString()); vars.put("userAccountID", response.ID); But i have found that BSF post processor reduces…
Yeasin Hossain
  • 769
  • 2
  • 6
  • 23
1
2
3
28 29