3

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?

1

2 Answers 2

1

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).

1
  • 1
    Can you add more details to improve the quality of your answer? Apr 6, 2015 at 21:55
1

In Java 8 Rhino has been replaced with Nadhorn, which allows some interaction between your Java code and Javascript. I don't know if it fits for your needs, but take a look into the following post:

http://winterbe.com/posts/2014/04/05/java8-nashorn-tutorial/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.