1

I have a proprietary Java API, which I want to call from my HTML/Javascript application. So I'm considering to use WebView or similar component to embed WebKit into resulting Java application.

What would be the best way to implement interface between Javascript and Java? Can I easily extend window DOM object in Java?

I'm going to run the application on the desktop (most likely Windows 7), but it's good to have as portable as possible as in the future I'll need to run the same app on different devices.

Fedor
  • 1,392
  • 1
  • 17
  • 30
  • Unfortunately http://stackoverflow.com/questions/48249/is-there-a-way-to-embed-a-browser-in-java and http://stackoverflow.com/questions/1454652/embed-browser-in-java-based-desktop-application do not fully answer my question. – Fedor Apr 30 '12 at 09:29
  • Why did you accept an answer for the second one then? And check out my answer on the first. – 11684 Apr 30 '12 at 09:38
  • That could be an answer to this question too. – 11684 Apr 30 '12 at 09:39

1 Answers1

1

If you don't want to use a server (which would make such a thing easy with ajax), you need to embed the javascript engine.

The best is probably to use the Rhino javascript engine (written entirely in java) :

http://www.mozilla.org/rhino/

There is also an integration of the very good V8 engine ( http://code.google.com/p/jav8/ ) but I don't know if this integration is complete or reliable.

Denys Séguret
  • 372,613
  • 87
  • 782
  • 758
  • You could post this answer here: too – 11684 Apr 30 '12 at 09:41
  • I was answering to "What would be the best way to implement interface between Javascript and Java". It seemed to me to be simpler not to integrate a browser (and I don't see the point to have two identical questions and answers so I think it's better to keep javascript engine in this question and to answer in the other one with the integration of browser). I agree with you, though, that the other question needs an acceptation. And I have some doubts and fears about the whole architecture of OP. – Denys Séguret Apr 30 '12 at 09:44
  • Thank you for the answer. My point is that I need both javascript engine and layout engine to run HTML/Javascript application inside my Java application. I may consider to use WebView without extending, simple web server running in the same application and let them communicate using ajax. – Fedor Apr 30 '12 at 10:19
  • I think i'll go with http://stackoverflow.com/questions/1454652/embed-browser-in-java-based-desktop-application Here is very good set of example http://www.eclipse.org/swt/snippets/#browser – Fedor Apr 30 '12 at 10:28