How to load a javascript file and run a javascript method in java? -
I'm using HTML code to render markdown code on client side.
But now I need to do the same thing on the server side to get the exact HTML code which is Java, I have to mark other Java Markdown libraries besides.
How can I load the "marked.js" file in java and run javascript code?
Marked Pierce (marked. Luxor ("** Hello, World **"));
2 options:
-
- See for example, re-presented below and embed Rhino yourself.
- Then edit it to fit your needs
OR:
Internal script directly in Java SE6 and above Use Agnine, which comes bundle with Rhino for you. See the runmarked examples below, depending on your requirements.
Runscript.Java / * * Licensed under MPL 1.1 / GPL 2.0 * / import org.mozilla.javascript. *; / ** * Ranscript: The simplest example of controlling Rhino execution. * * Collects your logic from the command line, * executes the script, and prints the result. * * @ Author Norris Boyd * / Public Class Random {Public Static Zero Main (String Array []) {// Creates a reference and enters. Context stores information about the execution environment of a script // reference cx = context.enter (); Try {// Start standard objects (objects, functions, etc.) // This script should be done before executing. Returns / a scope object that we later use in calls. Scriptable scope = cx.initStandardObjects (); // Collect logic in a string string S = ""; For (int i = 0; i & lt; args.length; i ++) {s + = args [i]; } // Now evaluate the string in which we have been object object result = cx.evaluateString (area, s, "", 1, faucet); // Convert the result to a string and print it. System.err.println (Context.toString (Results)); } Finally exit the {// context Context.exit (); }}}
runmarcade.java
Actually, I saw, and I would have written it exactly (except I could load it Using Libra directly with files.toString (file) using Google Guava) Please see the answer (and tell it if you find its answer useful).
Comments
Post a Comment