4

I have a project I maintain in Java that runs primarily as an applet. I am finding that Applets are simply unpractical and dangerous for browser games as most end-users ignorantly trust any applet because it runs in the browser (this is also what gives applets such a terrible reputation.)

I want to compile my Java project to JavaScript and use HTML5 for rendering. There are a couple problems I can see with this though...

  • Would it be feasible to translate Java reflection to JavaScript? I use Java's ScriptEngine module to run scripts in the engine.

  • How scalable is this idea of compiling to JavaScript. I have several pure Java dependencies that would also need to be compile to javascript (Specifically an Vorbis Audio SPI.) The code-base compiles to ~300kb (not sure if that helps gauge the size)

  • What are some other likely restrictions to encounter with this process?

Thanks.

Jeremy
  • 824
  • 1
  • 9
  • 21
  • 4
    While I'm sure someone has created a Java-to-JavaScript compiler (which probably doesn't work too great anyway), you're much better off manually rewriting your project to JavaScript for the sake of maintainability. – FThompson Sep 21 '13 at 16:54
  • Java is to JavaScript as car is to carpet. Of course it is feasible to port your code from Java to JavaScript, but it will not be as simple as porting to languages such as C# or Python. – azz Sep 21 '13 at 17:22
  • 1
    Porting the application to Javascript yourself takes perhaps 10 times as long as getting it to work in GWT. I would try GWT first and only do a manual port if the GWT port proves to be too slow. Best case you save 90% effort, worst case you do 10% more. – Matt Sep 30 '13 at 07:39
  • possible duplicate of [Any free tool to convert java to javascript](http://stackoverflow.com/questions/9429063/any-free-tool-to-convert-java-to-javascript) – chappjc Apr 18 '14 at 00:37

2 Answers2

5

Hmm.. GWT compiles java to JavaScript you can use it.

Another possibility would be using Rhino

Or just expose REST services and create an HTML5 web application using it.

Edit: BTW search in the forum. I found some questions like this one.

lastboy
  • 566
  • 4
  • 12
3

I found this tool called PlayN which may be what you're looking for. I've never used it before, but it looks promising. Of course, it may require rewriting your Java source to use their API, which means, as others have said, you're probably best off just manually porting to JavaScript.

Flight Odyssey
  • 2,267
  • 18
  • 25
  • 1
    PlayN is based on GWT, but makes it much easier to make games. There are libraries included for drawing stuff, touch interaction and sound. It can port to HTML5, but also to Android and Flash. – Matt Sep 30 '13 at 07:32