1

Is there a way to run a Java Applet in node.js, at server side?

It may sound crazy, but I am looking for a way to run a third party java applet on my node.js app server.

It is used to do a weird calculation that I am not willing to migrate to JavaScript code. Is this possible in any way? Any suggestions? I am in need to send the result of this calculation as a web page to the user, based on a request param.

I was initially thinking of how can I communicate between node.js and an Java Applet running standalone. Googled a bit but no success at all. Can someone suggest how to better google for it or point some good resources???

Renato Gama
  • 16,431
  • 12
  • 58
  • 92
  • Interfacing between node.js and Java [seems sort of doable](http://stackoverflow.com/questions/4729013/can-i-call-java-from-node-js-via-jni-and-how), once that works I think your best bet will be to extract the calculation code out of the applet - should be a class or a set of classes - and run the class that performs the calculation exactly like it is being done in the applet. Not easy, lots of work, but I think your chances of getting to a usable result are better than by trying to use the applet as-is. – fvu Jan 09 '13 at 23:03
  • Presumably there are remote desktop-type systems running the client as JavaScript in a browser. Certainly there are terminal emulators. Something like that could save you rewriting the presentation code. – Tom Hawtin - tackline Jan 09 '13 at 23:15
  • @TomHawtin-tackline I was looking for something more like this! Like a headless browser with support for JavaApplets, dont know it exists – Renato Gama Jan 09 '13 at 23:21
  • Do you just need to be able to perform the calculation in the java applet or do you need to perform actual user interaction on the applet from the client's browser? – Jannik Jochem Jan 10 '13 at 08:02
  • I need just to perform the calculation. No interaction needed. This applet has no UI actually. – Renato Gama Jan 10 '13 at 10:08
  • 1
    @RenatoGama..did u get solution with applet? i also want to apply same but in my side i want to use applet for video chat so is it possible to node.js with java? – Java D May 29 '13 at 04:58

1 Answers1

3

Using JNI will not help you as applets will not run in a headless environment. Applets are directly dependant on AWT so require a GUI environment to run.

Presuming that the license issues of the applet allow you to reuse the code, then my solution is to decompile the classes for the applet and use the generated java to create a normal java class with main that will run the desired calculations and return the result.

Unless the code is obfuscated, it's relatively simple to understand the decompiled code and should be relatively painless to adapt for what you wish to do.

Once you have your java code working from the command line you can then use the node-java project to call the java code from node.js and get your result.

Community
  • 1
  • 1
Metalskin
  • 3,998
  • 5
  • 37
  • 61