Questions tagged [javax.script]

A scripting API consists of interfaces and classes that define Java Scripting Engines and provides a framework for their use in Java applications.

The javax.script package available in Java 6+ allows the definition and execution of text based scripts supplied from strings, URLs, Readers or InputStreams. A standard J2SE JVM includes support for JavaScript. Support for additional languages is available either programmatically or through the Java Service Provider mechanism.

Available language support includes:

These implementations are available at the java.net Scripting project website.

58 questions
3
votes
1 answer

Return boolean value after a javaScript code is evaluated using javax.script.ScriptEngine object

I am using javax.script.* package to evaluate javascript in a Java File. I am using a ScriptEngine object to evaluate some javaScript code. The javaScript code returns a Boolean value. I am not sure how to capture the boolean value in the Java file.…
sony
  • 1,497
  • 7
  • 34
  • 49
3
votes
4 answers

Converting a Javascript array to a Java array

I'm trying to convert a Javascript array in Java to a Java array. I'm using the javax.script package. I tested this example here, but the type "NativeArray" was not recognized: https://stackoverflow.com/a/1433489/975097 How can I get the NativeArray…
Anderson Green
  • 25,996
  • 59
  • 164
  • 297
3
votes
1 answer

How to write to Nashorn error stream?

I use Nashorn scripts from a Java application. Java sets the context (including errorWriter) and everything just works fine... BUT i haven't found the way to write to the error Stream from the nashorn script. Does anyone know ? I tried to throw an…
xaevus
  • 53
  • 6
3
votes
2 answers

Nan comparison in Javascript with javax.scriptEngine on JDK8

According to IEEE 754 NaN equal comparison with any number should be false (both Java and JavaScript languages). But in the following code, using javax scriptEngine for JavaScript, a variable set to NaN compared with itself returns true. import…
fleroux
  • 31
  • 3
3
votes
3 answers

Why does getEngineByName(“js”) return null?

Whatever I try, getEngineByName() keeps returning null. Here's my code: final ScriptEngineManager manager = new ScriptEngineManager(); final ScriptEngine engine = manager.getEngineByName("js"); But engine is null after these lines. I also…
Alaa M.
  • 3,949
  • 7
  • 41
  • 81
2
votes
2 answers

Felix doesn't like javax.script

I'm writing an OSGI bundle using the javax.script package and am having some issues getting Felix to load the package correctly. When attempting to start the bundle, I'm getting: Failed bundle start for org.plugin.script.plugin-scripter [2]:…
Michael
  • 2,584
  • 2
  • 17
  • 17
2
votes
1 answer

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

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…
Nicolas Albert
  • 2,566
  • 1
  • 12
  • 16
2
votes
1 answer

How can I specify my own Rhino context in Java?

I'm trying to ensure that my Rhino scripts (running under Java 6) are strict so that if a script developer misspells an expression I want an exception to be thrown. Currently what happens is the expression simply evaluates to "undefined". Now…
sproketboy
  • 7,827
  • 17
  • 56
  • 81
2
votes
1 answer

Hello World example with javax on groovy script gives null pointer

I try to run the following: import javax.script.*; public class Main { public static void main(String[] args) throws Exception { ScriptEngineManager factory = new ScriptEngineManager(); ScriptEngine engine =…
greenTara
  • 53
  • 5
2
votes
1 answer

Calling custom script function with ScriptEngine from Java

I have same custom functions with the same names on different script files written in python, groovy and javascript. User can choose one of the scripts that want to use. I want to call functions from these scripts in generic way. …
cgrgcn
  • 351
  • 1
  • 6
  • 22
2
votes
2 answers

javax.script pass to javascript a Java method to use as a callback

I'm using javax.script to embed javascript code to a Java method. In my project the javascript takes care to send asynchronous http request through a websocket. Once a response is received I need to execute a callback function. I would like to…
Piero
  • 169
  • 1
  • 2
  • 10
2
votes
2 answers

How to create and use byte array with javax.script

Can we create primitive arrays like byte array or int array using javax.script?
Meera Menon
  • 59
  • 1
  • 3
2
votes
2 answers

Determine whether the current Javascript implementation is Rhino

I am using javax.script in Java, and I'd like to be able to detect whether the current Javascript implementation is Rhino. I'm doing this because I need to script to work properly on web pages as well as in Rhino. Javascript pseudocode: function…
Anderson Green
  • 25,996
  • 59
  • 164
  • 297
1
vote
2 answers

Using the javax.script package for javascript with an external src attribute

Say I have some javascript that if run in a browser would be typed like this...