nashorn

Troubleshooting Nashorn “Method code too large!” exception

风格不统一 提交于 2019-12-19 09:47:17
问题 Running jjs or ScriptEngine#eval on my JavaScript (https://gist.github.com/also/005fd7c200b20f012e10) crashes with this exception and no more details: Exception in thread "main" java.lang.RuntimeException: Method code too large! at jdk.internal.org.objectweb.asm.MethodWriter.getSize(MethodWriter.java:2065) at jdk.internal.org.objectweb.asm.ClassWriter.toByteArray(ClassWriter.java:856) at jdk.nashorn.internal.codegen.ClassEmitter.toByteArray(ClassEmitter.java:577) at jdk.nashorn.internal

How do you invoke a method in a Nashorn CompiledScript?

不想你离开。 提交于 2019-12-17 20:11:59
问题 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

Get a proper JSON literal in Java 8 using nashorn

梦想与她 提交于 2019-12-13 18:08:03
问题 I have a message that's to be sent over a socket, a string that represents a json: String message = "{\"sql\": \"{0}\"}"; I use MessageFormatter to put in the actual message from the user, and send it to the server. However, this needs to be a proper JSON string for the server to understand. After dabbling with manual escaping, realizing the SQL message can have nested quotes and whatnot, I understand I want to use a proper JSON tool to make sure the string is json-correct. I wish to use

How to make jdk.nashorn.api.scripting.JSObject visible in plugin [duplicate]

半腔热情 提交于 2019-12-13 17:51:39
问题 This question already has answers here : Access restriction: The type 'Application' is not API (restriction on required library rt.jar) (18 answers) Closed 4 years ago . I have an Eclipse RCP that interacts with java script. Now with Java 8, nashorn is used and code that depended on org.mozilla.javascript (plug-in org.mozilla.javascript_1.7.2.v201005080400.jar) must be changed to use jdk.nashorn.api.scripting. But when i try to use this import in Eclipse, it does not see it import jdk.nashorn

Access variable of ScriptContext using Nashorn JavaScript Engine (Java 8)

谁说胖子不能爱 提交于 2019-12-13 13:49:51
问题 I used the following code with the Rhino JavaScript engine in Java: @Test public void testRhino() throws ScriptException { final ScriptEngineManager factory = new ScriptEngineManager(); final ScriptEngine engine = factory.getEngineByName("rhino"); final String raw = "I am the raw value injected"; final ScriptContext ctx = new SimpleScriptContext(); ctx.setAttribute("raw", raw, ScriptContext.ENGINE_SCOPE); String script = "var result = 'I am a result';"; script += "java.lang.System.out.println

How to instantiate a Java class in JavaScript using Nashorn?

非 Y 不嫁゛ 提交于 2019-12-13 05:18:58
问题 Java Code package org.something; public class myClass{ static public Double getAvg(){ //Returns an average } } JavaScript Code var aJavaClass = Java.type('org.something.myClass'); var avg = aJavaClass.getAvg(); This is pretty much what I am attempting to do. The application I'm creating requires the Java portion to transfer a Double to JavaScript for use in an embedded browser. I'd looked into Nashorn and several tutorials for it, but while their code is fine, mine fails to run correctly

Nashorn profiler output format

狂风中的少年 提交于 2019-12-13 03:35:39
问题 Nashorn java script engine has built-in profiler which can be invoked like this: jjs -pcs profiled_script.js . This profiler produces a file named NashornProfile.txt . Here is an example line from this file: 0 dyn:getProp|getElem|getMethod:Object 764015 1 What is the format of this file and what is the meaning of each column? 回答1: The format is: Sequential line index Function name Total time spend inside function Hit count for the function This values are tab separated. Information taken from

Error rendering React.js using JVM Nashorn (Play Framework). I get “null is not a function”

▼魔方 西西 提交于 2019-12-12 08:48:29
问题 I've been going through this tutorial: http://tylermcginnis.com/reactjs-tutorial-a-comprehensive-guide-to-building-apps-with-react/, and run into an issue when rendering React on the JVM using Nashorn. My App.js file is as follows. It works correctly when running it on the client. Gives an error just when using Nashorn/JVM: var App = React.createClass({ getInitialState: function(){ return { name: 'Tyler McGinnis', friends: ['Jake Lingwall', 'Murphy Randall', 'Merrick Christensen'], } },

Java Nashorn - ClassNotFoundException - Java.type()

时间秒杀一切 提交于 2019-12-12 04:58:08
问题 I am currently creating a plugin for the Bukkit-Server, but i have a problem using the Nashorn scripting engine. I am evaluating the external javascript file from my Java-Plugin. I cant get my javascript to import the classes from my plugin, only standard java classes are working (like var JavaBool = Java.type('java.lang.Boolean'); , but not var Holder = Java.type('io.github.advtest1.js.JSHolder'); ) Whenever I try to load one of these I get the following error: Caused by: java.lang

How to extend Java class in Nashhorn JavaScript and add class member variables

纵饮孤独 提交于 2019-12-12 04:49:02
问题 I try to create an instance of a class that extends a Java class, and in that instance add some class member variables. Here's my attempt: var ui = Java.extend(javax.swing.JPanel, { cb : new JCheckBox("A checkbox", true), }); However, the Nashorn interpreter throws this error: "TypeError: function noSuchMethod () { [native code] } is not a constructor function" What am I doing wrong? Nashorn didn't complain when I added an instance of a custom class, like se.datadosen.util.Stopwatch, but it