Questions tagged [nashorn]

Nashorn is an open-source, JVM-based JavaScript engine. It replaced the Rhino JavaScript engine starting in Java 8.

Nashorn (pronounced Naz-horn, German word for "rhinoceros.") is an Oracle project included with JDK 8, intended to be a faster replacement for Rhino, the current JavaScript engine that ships with the JVM 7.

Nashorn can be used as a ScriptEngine or as a standalone tool (jjs).

Resources:

719 questions
55
votes
5 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,550
  • 2
  • 16
  • 22
49
votes
9 answers

Secure Nashorn JS Execution

How can I securely execute some user supplied JS code using Java8 Nashorn? The script extends some computations for some servlet based reports. The app has many different (untrusted) users. The scripts should only be able to access a Java Object and…
tom_ma
  • 618
  • 1
  • 6
  • 9
39
votes
1 answer

Nashorn and Scala future to JS Promise conversion

I have a server side implemented in Scala and React/Flux based front end. My services return Futures and they are handled within Scalatra's AsyncResult for JSON responses. For isomorphic/server side rendering setup I did not want to change services…
Petteri H
  • 11,779
  • 12
  • 64
  • 94
29
votes
7 answers

Switching from Rhino to Nashorn

I have a Java 7 project which makes a lot of use of Javascript for scripting various features. Until now I was using Rhino as script engine. I would now like to move to Java 8, which also means that I will replace Rhino by Nashorn. How compatible is…
Philipp
  • 67,764
  • 9
  • 118
  • 153
27
votes
1 answer

Java 8 Javascript Engine backwards compatibility

I am trying out Java 8 in my project and I am stuck in an error related to my build process. I am using ANT scripts and at some point i am using some javascript (embeded into ANT) to do some build specific operations. The part of the script that is…
nikkatsa
  • 1,751
  • 4
  • 26
  • 43
23
votes
3 answers

How to use Nashorn in Java 15 and later?

I have an existing Spring Boot application that is non-modular and uses Nashorn. The application works well on Java 14. After adding the Maven coordinates of the new Nashorn available for Java 15, the application fails while starting the script…
Aswath Murugan
  • 505
  • 2
  • 4
  • 12
20
votes
4 answers

How can I start coding with Oracle's Nashorn JS Engine and when will it replace Rhino in the OpenJDK?

I'm looking for a way to start playing around with Oracle's new Nashorn JavaScript Engine. I've DL'd the latest OpenJDK 8 (b65) and it appears that Rhino is still the only included script engine. Anyone know when (or in which build) Nashorn will…
max
  • 2,346
  • 4
  • 26
  • 34
19
votes
2 answers

JMeter Warning: Nashorn engine is planned to be removed from a future JDK release

When I run JMeter 5.1.1 recently downloaded, I see many times in terminal window: Warning: Nashorn engine is planned to be removed from a future JDK release I've used web search and found JEP 335: Deprecate the Nashorn JavaScript…
Alex Martian
  • 3,423
  • 7
  • 36
  • 71
19
votes
2 answers

How make Java 8 Nashorn fast?

I'm using Java 8 Nashorn to render CommonMark to HTML server side. If I compile and cache and reuse a CompiledScript, a certain page takes 5 minutes to render. However, if I instead use eval, and cache and reuse the script engine, rendering the same…
KajMagnus
  • 11,308
  • 15
  • 79
  • 127
19
votes
3 answers

Nashorn bug when calling overloaded method with varargs parameter

Assume the following API: package nashorn.test; public class API { public static void test(String string) { throw new RuntimeException("Don't call this"); } public static void test(Integer... args) { …
Lukas Eder
  • 211,314
  • 129
  • 689
  • 1,509
17
votes
1 answer

Nashorn in Java 11 behaves differently from Java 8 when evaluating named functions

I have a Java application that allows users to manipulate certain objects at runtime by defining a JavaScript function. We are currently doing this with Nashorn in Java 8, but we are looking to move to Java 11. Once we're on Java 11 we'll be able to…
Joel Westberg
  • 2,656
  • 1
  • 21
  • 27
16
votes
2 answers

Nashorn alternative for Java 11

I am using the Nashorn JavaScript Engine in Java 11 which works fine except it will be deprecated soon. I have tried GraalVM which I find quite worse as it takes 13-14 seconds to execute a simple expression (e.g. 2+3). Is there any other alternative…
Sohaib Zafar
  • 183
  • 1
  • 1
  • 6
16
votes
1 answer

Nashorn performance on JDK 9 and JDK 10

If you interpret the moment.js library using Nashorn on JDK 8, it runs in a couple of seconds: time .../JDK8/bin/jjs moment-with-locales-2.22.2.js real 0m2.644s user 0m10.059s sys 0m0.287s But do the same on JDK 9 or 10, and it's…
16
votes
1 answer

Java 8 Nashorn: Console pretty unusable

I am using Java 8 build 1.8.0-b132 on OSX 10.9.2. I am playing with Nashorn the new JavaScript runtime in Java 8. I am using Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/bin/jjs but unfortunately jjs is pretty unusable in interactive…
jbandi
  • 17,499
  • 9
  • 69
  • 81
15
votes
2 answers

Java, nashorn accessing another js file

Is it possible to include one js from another with java nashorn engine? ScriptEngine engine = new ScriptEngineManager().getEngineByName("Nashorn"); InputStreamReader rs = new InputStreamReader(new FileInputStream(new…
hnnn
  • 504
  • 2
  • 7
  • 24
1
2 3
47 48