Search code examples
javanode.jsearjava-server

Can I package a Node.js App as a Java EAR


Let's imagine that your company asked to develop a real-time chat application and wanted it to be finished in hours. Since you already know that it's super duper easy with Node.js, you developed it in Node.js but the company uses Java Application Servers(like WebSphere, JBoss or WebLogic).

So the server administrator expects .EAR files to deploy.

Is there any way to provide an .EAR file that runs your Node.js app behind?


Solution

  • this is so frigging dirty that any sane checks on the released EAR should kill you on place. that being said, yes, it's possible. you have to know a bit of things first.

    1. is the target JVM is enough priviliged to run processes or security on the execute right sufficently lax to enable the JVM to execute shell process by using it's API methods. (i'm talking about Java security, not OS security)

    2. you must know first hand exactly which type of OS the ear container is running on.

    3. the EAR/WAR must be "expanded" to a real filesystem known by the OS.

    4. you must know if the credential under which the ear container have enough privilege to execute a OS command.

    once you know exactly those four points, this is no biggie to use the Process java API to execute a Node.js process that the executable (statically linked and OS compatible) is conveniently to a known position...

    even as Bruno Grieder said, sharing port is not possible, so you'll just have the web application acting as a front proxy for the "real" application running on Node.js, HTTP or HTTPS being not relevant at all as the final communication between the web application container and the web application itself is no longer encrypted.

    awwww... so cute ... :) but, you have to know that using a sneaky method like this in company environment, is not a good thing.