I am writing a standalone application in Java that needs to be able to call custom Javascript APIs? Is there a way to call custom Javascript APIs in Java?
4 Answers
In a standalone app: should be possible by using Rhino.
2 Comments
Stephen Watkins
This looks like a good thing. Perhaps for the custom APIs, it would be good to use the Rhino Javascript Compiler. Then, use those classes in my Java code?
Mark Porter
For the purposes of scripting your application, it is better to embed Rhino in your application and then interpret the scripts at run time. That would allow your users to create "macros" that control your app. Where you store the scripts doesn't matter (resource bundle, files, DB etc) If you compile your JS to java class files using the compiler, then they aren't really any different then any other Java class file, which is probably not what you want.
JSon could be your one stop. Let me know if you are looking for this?
1 Comment
Michael Borgwardt
I guess this answer assumes that the "Javascript APIs" in question are services accessible through the internet.
Aside from the name, javascript and java have no relationship whatsoever.
4 Comments
Fredrik
I didn't mod you down but I would guess whoever did so did it because it is not true anymore...
Rakesh Juyal
i think i will never be able to understand why the hell on SO, do somebody downvote sensible answers as well
Michael Borgwardt
This answer is not sensible, it is irrelevant. stjowa is clearly aware that Java and Javascript are different beasts.
Peter Recore
@Fredrik. Could you elaborate on the relationship? Surely you can use both in the same project, and things like Rhino let them interact, but as languages they are independent, and javascript is really just another name for ecmascript anyway.