VMware Tanzu Archive

 View Only

 How to execute a java jar from a node js application ?

Anshul Saxena's profile image
Anshul Saxena posted Aug 23, 2018 08:20 AM

I have a node js backend , Angular Front End application. On click of a button I am executing a java -jar via node application file whose output is redirected to the node app.

The application was working perfectly on a normal server because the path of the jar file is specified.

How to provide the same with the pcf ?

Daniel Mikusa's profile image
Daniel Mikusa

This is a little tricky because the Node.js buildpack isn't going to install a JVM for you & that would be a prerequisite for running a JAR.

 

What you would need to do is use the multi-buildpack support in Cloud Foundry.

 

https://docs.cloudfoundry.org/buildpacks/use-multiple-buildpacks.html

 

This would allow you to run two buildpacks, one which could provide Node.js & one that could provide Java.

 

That brings us to the next issue. A buildpack has to support being either a supply-only (just adds dependencies) or a supply & finalize (supply dependencies & know how to start your app) buildpack. At the moment, the Java buildpack can only be used as the latter. This means, it's not going to work for your use case because you need the Nodejs buildpack to be the final buildpack so it can start your app.

 

If you don't have very specific requirements in terms of the JVM that is used, you could use the Apt buildpack to do install Java. The Apt buildpack takes a list of apt packages and will install them for you. You could use this to install Java. Java would then be on the path & you should be able to run it from your node app.

 

https://github.com/cloudfoundry/apt-buildpack

 

Hope that helps!

Daniel Mikusa's profile image
Daniel Mikusa

Oh, another option would be using Docker. You can always deploy a Docker image that you create but then you are responsible for keeping all your requirements up-to-date. The platform can no longer help you via buildpacks.