简体   繁体   English

我可以将Node.js应用程序打包为Java EAR吗

[英]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). 因为您已经知道使用Node.js超级简单,所以您在Node.js中开发了它,但是该公司使用Java应用服务器(例如WebSphere,JBoss或WebLogic)。

So the server administrator expects .EAR files to deploy. 因此,服务器管理员希望部署.EAR文件。

Is there any way to provide an .EAR file that runs your Node.js app behind? 有什么方法可以提供一个在后方运行Node.js应用程序的.EAR文件吗?

this is so frigging dirty that any sane checks on the released EAR should kill you on place. 这是如此肮脏,以至于对释放的EAR进行任何理智的检查都应该杀死您。 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. 是指目标JVM有足够的特权来在执行权上充分运行进程或安全性,从而使JVM通过使用其API方法来执行Shell进程。 (i'm talking about Java security, not OS security) (我说的是Java安全性,而不是OS安全性)

  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. EAR / WAR必须“扩展”到OS已知的真实文件系统。

  4. you must know if the credential under which the ear container have enough privilege to execute a OS command. 您必须知道耳容器是否具有足够的特权来执行OS命令。

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... 一旦您确切地知道了这四点,就可以使用Process Java API执行Node.js进程,将可执行文件(静态链接并与OS兼容)方便地放置在已知位置上并不是什么大事...

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. 即使像Bruno Grieder所说的那样,也不可能共享端口,所以您只需要让Web应用程序充当Node.js上运行的“真实”应用程序的前端代理,HTTP或HTTPS就根本与最终通信无关Web应用程序容器和Web应用程序本身之间的密码不再加密。

awwww... so cute ... :) but, you have to know that using a sneaky method like this in company environment, is not a good thing. awwww ...太可爱了... :)但是,您必须知道,在公司环境中使用这种偷偷摸摸的方法并不是一件好事。

No. 没有。

You cannot properly package a "pre-installed" nodeJS inside an ear. 您无法在耳朵内正确打包“预安装” nodeJS。

NodeJS installation differs between Windows and Linux; Windows和Linux之间的NodeJS安装有所不同。 the EAR would not be portable. EAR不能携带。

On a side note, I would not like to be in your shoes, should the server administrators learn that you are packaging executables not meant to be run on the JVM, inside the EAR. 附带说明一下,如果服务器管理员得知您正在打包不是要在EAR内部的JVM上运行的可执行文件,则我不愿为所欲为。

(note1: as noted in the comments above by @mlan, it would be impossible to share ports between the JVM and nodejs process - faking it would require a fronting reverse proxy dispatching HTTP requests, assuming all traffic is HTTP) (注1:如@mlan在上面的注释中所指出的那样,不可能在JVM和nodejs进程之间共享端口-假装它需要前端反向代理来调度HTTP请求,假设所有流量都是HTTP)

(note2: don't put me wrong, you can put anything in a EAR, including executables that you trigger from Java using ProcessBuilder for instance, but that a last resort workaround) (注2:别误会,您可以将任何东西放到EAR中,包括例如您使用ProcessBuilder从Java触发的可执行文件,但这是最后的解决方法)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM