Nashorn compiled output as a Java class

Is it possible to convert the result of computing Nashorn Javascript into a Java class file that will be called later? (e.g. JSP -> Java -> Class File)

I have a Javascript file that Nashorn uses to generate HTML output. The javascript file has different functions for each component to generate HTML output for each of them. These component functions are dynamically called using the renderServer function, which accepts the component name and JSON data for this component.

private ScriptEngine nashorn;
ScriptEngineManager scriptEngineManager = new ScriptEngineManager(null);
        this.nashorn = scriptEngineManager.getEngineByName("nashorn");  
         this.nashorn.eval(new FileReader(jsFile);
String compName="myComponent1";// Component 1 name 
String jsonData="{....}";// JSON data input for myComponent
String formatted = "JSON.parse('" + jsonData + "')";

String htmlRender = "renderServer(\"" + myComponent1 + "\"," + formatted + ");";

Object finalResult = nashorn.eval(htmlRender);

I want to generate compiled evaluation output and call the java class, instead of doing nashorn.eval every time, passing the component name and json input. Can this be achieved?

+4
source share
1

. -, nashorn, Java-. / "- " , Nashorn. java-.

+1

Source: https://habr.com/ru/post/1689389/


All Articles