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.

4
  • 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
    Commented Sep 21, 2013 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
    Commented Sep 21, 2013 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
    Commented Sep 30, 2013 at 7:39
  • possible duplicate of Any free tool to convert java to javascript
    – chappjc
    Commented Apr 18, 2014 at 0:37

2 Answers 2

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.

1
  • Rhino? Isn't that the opposite of what was originally asked? Commented May 15, 2017 at 18:31
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.

1
  • 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
    Commented Sep 30, 2013 at 7:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.