1

I'm trying to execute a Jar file from a Javascript file to get the console output. I've pushed both files to Heroku, but when I try calling the function in the js file, I get this error:

/bin/sh: 1: java: not found exec error: Error: Command failed: java -jar -Xms1024m MongoConnector-all abaabaa

[31merror[39m: RangeError: Maximum call stack size exceeded

This is the code that I have:

const runCoreSearch = function(searchInputString) {
  const exec = require('child_process').exec;
  //child = exec('/usr/bin/java -jar ~/Applications/Mongo Connector-all.jar' + rakeInputString,
  const child = exec('java -jar -Xms1024m MongoConnector-all ' + searchInputString,
  function (error, stdout, stderr){
...

On their website (https://devcenter.heroku.com/articles/deploying-executable-jar-files) it says to use the command "heroku deploy:", but I'm not trying to deploy a Java project, just execute the jar from a node.js project. Any ideas?

2 Answers 2

6

You'll need to add the heroku/jvm buildpack to your app and redeploy:

$ heroku buildpacks:add heroku/jvm
$ git commit -m "redeploy" --allow-empty
$ git push heroku master

This will install the java command into your dyno.

Sign up to request clarification or add additional context in comments.

Comments

1

I did codefinger's solution but got the following error :

Picked up JAVA_TOOL_OPTIONS -Xmx300m -Xss512k -Dfile.encoding=UTF-8 
Error : A JNI error has occured, please check you installation and try again 
Exception in thread "main" java.lang.UnsupportedClassVersionError: myClass has been compiled by a more recent version of the Java Runtime (class file version 54.0)...this java version only recognize version up to 52.0

To fix this,

  • Create a file named system.properties in the root of your folder
  • Add java.runtime.version=XX where XX is the current version of your jdk/jre
  • Push the code to heroku

Documentation : https://devcenter.heroku.com/articles/java-support#supported-java-versions

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.