0

I have developed a Java applet which opens a URL connection to some different server. The applet then retrieves contents of the HTML page and do some processing and then shows to user. Can I cross-compile it to JavaScript using GWT?

Marcel Korpel
  • 21,536
  • 6
  • 60
  • 80
akp
  • 1,823
  • 7
  • 26
  • 29
  • 1
    You want the ability to compile the same source either into an Applet or a GWT app? No, that is not possible. For a variety of reasons, not least of which they share completely unrelated frameworks for UI building. – Kirk Woll Sep 17 '10 at 16:08
  • basically i want to port core logic which i wrote inside applet to java script using GWT.Can this be done? – akp Sep 17 '10 at 16:10
  • main thing is that it involes geting contents of a webpage frm a specific uri – akp Sep 17 '10 at 16:10
  • I do understand that why i used the word crosscompile. – akp Sep 17 '10 at 16:19
  • You also know that a signed applet can access foreign URLs and javascript cannot out of the box do the same? Are you not just looking for a proxy on the server that can serve an apple or an AJAX script the content of URLs? – mplungjan Sep 17 '10 at 16:24
  • Did you look at the link in this discussion about GWT JRE emulation> http://stackoverflow.com/questions/2771167/convert-java-applet-code-in-to-java-script – mplungjan Sep 17 '10 at 16:26
  • Possible duplicate: http://stackoverflow.com/questions/3360296/java-to-javascript-compiler – Anderson Green Mar 03 '13 at 04:41

1 Answers1

3

Cross compile: No. Port: Probably. Depends on your constraints.

You won't be able to do a straight recompile and have it "just work" (GWT only supports a subset of the JRE and any UI stuff definitely isn't a part of it) but you might be able to port some of your logic over. If you're using XPath to pull content out of the page, that code most likely will need to be redone as well. There's a GWT wrapper for Sarissa that works pretty well.

Also, since the requested page is going to be on a different server, you'll need to set up some method of doing a cross site request. So either browser hacks or a proxy on the hosting server.

j flemm
  • 1,989
  • 1
  • 12
  • 6