node.js and Java - which approach?

97 views
Skip to first unread message

O haya

unread,
Sep 22, 2016, 2:09:44 PM9/22/16
to nodejs
Hi,

I am looking to port a project that we have to using node.js.  The current project consists mainly of a homegrown, standalone Java app as a threaded web server.  The thing is that this app also has to integrate with (call out to) a COTS (commercial off-the-shelf) product, via a Java API that they provide.  In other words, my Java app calls out to the COTS Java API.

Now, I want to try to re-implement that threaded web server using node.js, but I also need the web server app to integrate with that COTS product's Java API, so I've been researching how to do this. 

From what I've seen, there are a number of approaches, but the one that seemed most interesting was node-java (https://github.com/joeferner/node-java), so I started trying to work with that (I know that there's a separate group for node-java, but (a) I think my question(s) are more generic and (b) there doesn't seem to be much activity on that node-java group, so I am hoping it's ok to ask here).

I had a heck of a time getting node-java to build, but I finally got it working (I think) by standing up a new CENTOS 7 instance and building it there, under Java JDK 1.7.

Now, I am trying to port some of the Java interface part of my Java code to node.js+node-java and having some problems.  

Is it ok to ask about that (those problems) here?

Also, I'm kind of getting the feeling that node-java isn't the way to go, because it's not supported, so I am thinking about what other approaches that I can use instead of node-java?

I've seen references to nashorn and rhino, but I am not clear what those are vis-a-vis node.js?  Are they replacements for node.js in whole?

FYI, the reason for that last question is I am mandated to work with node.js, so if they are replacements for node.js, that would be a no-go for me now.

Also, I have seen some references that rhino/nashorn use messaging, rather than JNI, to provide the Javascript-to-Java bridge.  Is that correct?  The reason for this question is that one of my requirements is performance-related, and I would be concerned of performance if the bridging was via messaging approach.

Sorry for lots of questions :(!!

Thanks,
Jim

ad...@cs.miami.edu

unread,
Oct 6, 2016, 1:15:27 PM10/6/16
to nodejs
Hi

Since you already have much Java in the project you may want to look into vertx. It is very similar to node but runs on nvm. I won't say too much more as this is a node group . But it may be worth considering.


Adam

FleetCommand

unread,
Dec 3, 2016, 10:17:37 PM12/3/16
to nodejs
very interesting and unique problem , if you really have no choice other than node + existing java components. I recommend not to merge the two using a bridge which inject or adopts various objects and types between the two languages as it could be a mess and unmanageable going forward. I suggest a simpler approch
1. implement web app in node as usual
2. create runnable jar (or muliple .jar files based on your modules or components), which wraps your java functionality (EJB or Java specific calls) 
3. execute that runnable jar using child process, you can pass data in arguments 
4. now problem is how to get the result back , well you can try capturing stdout of child process if result must be processed inline of client's request and response   AND/OR let that jar call back your server on localhost if its not inline :-) 

Hope it helps,
Amit
Reply all
Reply to author
Forward
0 new messages