I know about JSNI but the problem is that your whole project has to use and conf
ID: 656563 • Letter: I
Question
I know about JSNI but the problem is that your whole project has to use and conform to GWT in order to use it. I'm looking for something that I can make a call to which can take the Javascript code I've written in Java and generate it into a file or series of files.
I know that scripting engines can be used to execute javascript code, however, I have not found any that actually allow you to build up your javascript using Java. Most of them require javascript in the form of a string.
Are there any libraries that offer this functionality?
Explanation / Answer
Yes, you can use the Rhino engine. Java can handle javascript if you use a special variable called a ScriptEngine which enables us to handle script code neatly inside Java, and also execute javascript inside Java if we wish.
The way I've been doing it is with Spring MVC which has this builtin, but you can definitely use a standalone scriptengine to do whatever you like with your Javascript inside your Java code and adhere to standards and conventions. It's also an interesting project from a computer science point of view and my personal interest (compilers and execution environments).