Tomás Müller
Tomás Müller

Reputation: 314

Sinatra Jruby Heroku - jruby: No such file or directory -- trinidad (LoadError)

I'm trying to get this application running: github.com/Soliah/sinatra-jruby-heroku.git

One update was necessary according to this release note from Heroku:

http://devcenter.heroku.com/articles/release-note-java-2011-09-29

The build goes fine, without any errors. Bellow some log parts:

   [INFO] --- jruby-rake-plugin:1.6.3:jruby (install-bundler) @ jruby-heroku ---
   [INFO] Successfully installed bundler-1.0.21
   [INFO] 1 gem installed
   [INFO] 
   [INFO] --- jruby-rake-plugin:1.6.3:jruby (bundle-install) @ jruby-heroku ---
   [INFO] Fetching source index for http://rubygems.org/
   [INFO] Installing jruby-rack (1.0.10) 
   [INFO] Installing rack (1.3.2) 
   [INFO] Installing tilt (1.3.3) 
   [INFO] Installing sinatra (1.2.6) 
   [INFO] Installing trinidad_jars (1.0.1) 
   [INFO] Installing trinidad (1.2.3) 
   [INFO] Using bundler (1.0.21) 
   [INFO] Your bundle is complete! It was installed into ./vendor/bundle

   (...)

   [INFO] BUILD SUCCESS
   [INFO] ------------------------------------------------------------------------
   [INFO] Total time: 33.408s
   [INFO] Finished at: Tue Jan 31 10:58:03 UTC 2012
   [INFO] Final Memory: 9M/490M
   [INFO] ------------------------------------------------------------------------
  -----> Discovering process types
         Procfile declares types -> jruby, web
  -----> Compiled slug size is 18.6MB
  -----> Launching... done, v5
         http://jrubyandjava.herokuapp.com deployed to Heroku

But when I access the deployed application. An application error occurs.

Here is the log, with the error:

  $ heroku logs
  2012-01-31T10:57:21+00:00 heroku[slugc]: Slug compilation started
  2012-01-31T10:58:13+00:00 heroku[web.1]: State changed from created to starting
  2012-01-31T10:58:19+00:00 heroku[web.1]: Starting process with command `sh script/jruby -S trinidad -p 52233`
  2012-01-31T10:58:20+00:00 app[web.1]: Classpath is: :/app/etc:/app/target/dependency/jruby-complete.jar
  2012-01-31T10:58:21+00:00 app[web.1]: jruby: No such file or directory -- trinidad (LoadError)
  2012-01-31T10:58:23+00:00 heroku[web.1]: State changed from starting to crashed
  2012-01-31T10:58:23+00:00 heroku[web.1]: State changed from crashed to created
  2012-01-31T10:58:23+00:00 heroku[web.1]: State changed from created to starting
  2012-01-31T10:58:23+00:00 heroku[web.1]: Process exited
  2012-01-31T10:58:28+00:00 heroku[web.1]: Starting process with command `sh script/jruby -S trinidad -p 26224`
  2012-01-31T10:58:28+00:00 app[web.1]: Classpath is: :/app/etc:/app/target/dependency/jruby-complete.jar
  2012-01-31T10:58:31+00:00 app[web.1]: jruby: No such file or directory -- trinidad (LoadError)
  2012-01-31T10:58:32+00:00 heroku[web.1]: State changed from starting to crashed
  2012-01-31T10:58:33+00:00 heroku[web.1]: Process exited
  2012-01-31T10:58:33+00:00 heroku[router]: Error H10 (App crashed) -> GET jrubyandjava.herokuapp.com/ dyno= queue= wait= service= status=503 bytes=

It seems that JRuby is not finding the gems. But I've tried all kinds of configurations (in script/jruby, heroku config:add, Procfile, etc.) and no one worked.

One more thing: this is the actual heroku config output (stack cedar).

  $ heroku config
  DATABASE_URL        => postgres://kfgubrhars:[email protected]/kfgubrhars
  JAVA_OPTS           => -Xmx384m -Xss512k -XX:+UseCompressedOops
  MAVEN_OPTS          => -Xmx384m -Xss512k -XX:+UseCompressedOops
  PATH                => /usr/local/bin:/usr/bin:/bin
  SHARED_DATABASE_URL => postgres://kfgubrhars:[email protected]/kfgubrhars

Here is the updated repository: https://github.com/tomasmuller/sinatra-jruby-heroku

Thank's in advance!

Upvotes: 3

Views: 1565

Answers (3)

Michael van Rooijen
Michael van Rooijen

Reputation: 6733

As of Bundler 1.2 you are now able to specify the Ruby implementation and version in your Gemfile. The nice thing about this is that Heroku will understand these settings and prepare the your Heroku application for your environment.

Take this Gemfile for example:

source "https://rubygems.org"

ruby "1.9.3"

gem "rails"
gem "puma"

What's cool about this is that by default Celadon Cedar uses Ruby 1.9.2. However, when you specify ruby "1.9.3" in the Gemfile it'll actually compile Ruby 1.9.3 for your Heroku environment.

Now, if you want to add a different Ruby implementation to your Heroku environment, you can do so like this:

source "https://rubygems.org"

ruby "1.9.3", :engine => "jruby", :engine_version => "1.7.0.preview1"

gem "rails"
gem "puma"

Now it'll install and use JRuby 1.7.0.preview1 in Ruby 1.9 mode for your Heroku application upon deployment. It'll also even define the proper JVM options in the Heroku environment variables.

Best of all is that this comes with the official Heroku buildpack, so there is no need to switch to a 3rd party buildpack to get the JRuby/JVM going on Heroku. Although I haven't gotten it to work yet, this should also work with Rubinius, but I believe it's currently bugged. Either that, or I'm doing it wrong.

This is in my opinion an awesome and scalable feature. Just define the Ruby implementation/version/mode you're using in your Gemfile along with your other dependencies and Heroku will ensure the environment is prepared.


It is no longer necessary to use a workaround or use 3rd party buildpacks using this method. It is also no longer necessary to create a hacky Jemfile. Instead, just do everything as you would normally do with MRI, keep the Gemfile, don't use 3rd party buildpacks, just define the Ruby implementation/runtime in the Gemfile via the ruby method and Heroku should take care of things.

Upvotes: 0

Tomás Müller
Tomás Müller

Reputation: 314

Ok! I found the solution. Here are the steps:

  • Adjust the GEM_HOME, in script/jruby to:

    GEM_HOME="$APPDIR"/vendor/bundle
    
  • Created the script/bundle, with ENV['GEM_HOME'] and ENV['GEM_PATH'] pointing to 'vendor/bundle' dir.

  • Adjusted the executions of jruby-rake-plugin, in pom.xml:

    install-bundler: <args>-S gem install bundler --no-ri --no-rdoc --install-dir vendor/bundle</args>
    
    bundle-install: <args>script/bundle install --without development:test</args>
    

Upvotes: 1

Soliah
Soliah

Reputation: 1396

There's been a recent change to where the gems get installed. The launcher script/jruby expects the gems to be in .gems but it looks like that has now changed to vender/bundle.

Try changing the line https://github.com/tomasmuller/sinatra-jruby-heroku/blob/master/script/jruby#L94 to export GEM_HOME="$APPDIR"/vender/bundle instead.

I've been meaning to update my blog post with these changes but just haven't got around to it.

Upvotes: 0

Related Questions