Can't deploy to Heroku the app with RJB gem

2.1k Views Asked by At

I've set the JAVA_HOME variable

heroku config:add JAVA_HOME=/usr/lib/jvm/java-6-openjdk

checked that heroku config shows this variable with value, then pushed:

git push heroku master

and still get

JAVA_HOME is not set

error while bundler is installing RJB gem.

I can successfully deploy the same source to another Heroku application, and all environment variables are the same.

What is wrong?

6

There are 6 best solutions below

2
On BEST ANSWER

I had the same question, and in case anyone else wants to know, this is what Heroku told me:

By default the config variables aren't made available when the application is compiled - only at runtime.

You can change this by making sure you have the latest heroku gem install, then enable the user_env_compile lab flag

$ heroku labs:enable user-env-compile

this will make JAVA_HOME available when the gem installs, hopefully getting you past this issue.

0
On

First find JAVA_HOME PATH by using,

heroku run 'which java |xargs  readlink -f  | sed "s:bin/java::"'

It will return you,

usr/lib/jvm/java-6-openjdk/jre

Using this now you came know about JAVA_HOME path on heroku. Now set JAVA_HOME path in heroku and in Gemfile

on heroku cli :

heroku config:add JAVA_HOME=/usr/lib/jvm/java-6-openjdk

In Gemfile on top :

java_home = '/usr/lib/jvm/java-6-openjdk'
ENV['JAVA_HOME'] = java_home if Dir.exist?(java_home)
0
On

Got Heroku to install gems that depend on $JAVA_HOME by adding the following to my Gemfile:

# set JAVA_HOME so Heroku will install gems that need it
heroku_java_home = '/usr/lib/jvm/java-6-openjdk'
ENV['JAVA_HOME'] = heroku_java_home if Dir.exist?(heroku_java_home)
0
On

for migration from heroku cedar-14 to heroku-16 or heroku-18

$ heroku config:unset JAVA_HOME #remove JAVA_HOME env if exists
$ heroku stack:set heroku-18
$ heroku buildpacks:add --index 1 heroku/jvm
$ git push heroku master
0
On

To deploy to the heroku-20 stack, make sure you add the following build packs in this order:

heroku buildpacks:add heroku/jvm
heroku buildpacks:add heroku/ruby

You do NOT need to set JAVA_HOME manually with heroku-20. Nor will Heroku set it for you. The variable is already internally available to rjb when it is being installed.

Your final result should look like this:

enter image description here

3
On

Have you tried deploying your app to a different stack?

I did a little searching and this seems to fit your explanation. https://github.com/carlhuda/bundler/issues/1742

probably yours report, isn't it?

I would advice you to contact Heroku and ask them to look into it.

It seems like it's missing dependencies which may, not be available on your current stack.