Heroku run Jar from Javascript



我正在尝试从Javascript文件执行Jar文件以获取控制台输出。我已经将这两个文件推送到 Heroku,但是当我尝试在 js 文件中调用函数时,出现此错误:

/

bin/sh: 1: java: 未找到 exec 错误: 错误: 命令失败: java -罐子 -Xms1024m 蒙古连接器-所有 abaabaa

[

31m错误[39m: 范围错误: 超出最大调用堆栈大小

这是我的代码:

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){
...

在他们的网站(https://devcenter.heroku.com/articles/deploying-executable-jar-files)上,它说要使用命令"heroku deploy:",但我不是要部署Java项目,只是从node.js项目执行jar。有什么想法吗?

您需要

heroku/jvm构建包添加到您的应用程序中并重新部署:

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

这会将java命令安装到您的测功机中。

我做了代码手指的解决方案,但得到以下错误:

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

要解决此问题,

  • 在文件夹的根目录中创建一个名为 system.properties 的文件
  • 添加 java.runtime.version=XX,其中 XX 是 jdk/jre 的当前版本
  • 将代码推送到 heroku

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

最新更新