views:

69

answers:

4

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?

+1  A: 

In a browser?

If your applet exposes a scriptable interface, yes you can.

jldupont
+3  A: 

In a standalone app: should be possible by using Rhino.

Michael Borgwardt
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?
stjowa
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.
Mark Porter
A: 

Aside from the name, javascript and java have no relationship whatsoever.

Joel Coehoorn
I didn't mod you down but I would guess whoever did so did it because it is not true anymore...
Fredrik
i think i will never be able to understand why the hell on SO, do somebody downvote sensible answers as well
Rakesh Juyal
This answer is not sensible, it is irrelevant. stjowa is clearly aware that Java and Javascript are different beasts.
Michael Borgwardt
@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.
Peter Recore
A: 

JSon could be your one stop. Let me know if you are looking for this?

DKSRathore
.............hein?
jldupont
I guess this answer assumes that the "Javascript APIs" in question are services accessible through the internet.
Michael Borgwardt