Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deploy JRuby Rails 3.1.x on Heroku?

I want to be able to deply a jruby rails 3.1 app to Heroku.

Heroku now suports Java: http://blog.heroku.com/archives/2011/08/25/java/ Supposedly, it should be possible to deploy a JRuby rails application. There's a tutorial here for plain java: http://devcenter.heroku.com/articles/java and another here: http://devcenter.heroku.com/articles/spring-mvc-hibernate

Here's a tutorial for a JRuby Sinatra app on Heroku: http://chris.chowie.net/2011/08/28/Sinatra-with-JRuby-on-Heroku/ In order to get this to work, I had use non-jruby ruby when running heroku, as heroku crashes if rvm uses jruby.

In order to run the command

mvn package

I had to run this:

bundle --gemfile=/home/justin/github/sinatra-jruby-heroku/Jemfile install temple
bundle --gemfile=/home/justin/github/sinatra-jruby-heroku/Jemfile update

I created the app:

heroku create jg1-sinatra --stack cedar

I pushed the file to heroku, but when the app started, it crashed. :(

Any advice? I'm guessing that it won't be long before Heroku has a tutorial on this.

Log file from Heroku:

2011-11-21T08:30:40+00:00 heroku[slugc]: Slug compilation started
2011-11-21T08:31:17+00:00 heroku[api]: Deploy 3bccec5 by [email protected]
2011-11-21T08:31:17+00:00 heroku[api]: Release v7 created by [email protected]
2011-11-21T08:31:18+00:00 heroku[web.1]: State changed from crashed to created
2011-11-21T08:31:18+00:00 heroku[slugc]: Slug compilation finished
2011-11-21T08:31:20+00:00 heroku[web.1]: Starting process with command `sh script/jruby -S trinidad -p 17687`
2011-11-21T08:31:20+00:00 app[web.1]: Classpath is: :/app/etc:/.m2/repository/org/jruby/jruby-complete/1.6.3/jruby-complete-1.6.3.jar
2011-11-21T08:31:20+00:00 app[web.1]: Exception in thread "main" java.lang.NoClassDefFoundError: org/jruby/Main
2011-11-21T08:31:20+00:00 app[web.1]: Caused by: java.lang.ClassNotFoundException: org.jruby.Main
2011-11-21T08:31:20+00:00 app[web.1]:   at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
2011-11-21T08:31:20+00:00 app[web.1]:   at java.security.AccessController.doPrivileged(Native Method)
2011-11-21T08:31:20+00:00 app[web.1]:   at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
2011-11-21T08:31:20+00:00 app[web.1]:   at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
2011-11-21T08:31:20+00:00 app[web.1]:   at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
2011-11-21T08:31:20+00:00 app[web.1]:   at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
2011-11-21T08:31:20+00:00 app[web.1]: Could not find the main class: org.jruby.Main. Program will exit.
2011-11-21T08:31:20+00:00 heroku[web.1]: Process exited
2011-11-21T08:31:21+00:00 heroku[web.1]: State changed from starting to crashed
like image 722
justingordon Avatar asked Nov 21 '11 08:11

justingordon


People also ask

What is heroku in Ruby on Rails?

Deploy Ruby on Rails API on Heroku Heroku is a platform that enables developers to build, run, and operate applications entirely on the cloud with multi-language support for Ruby, Go, Scala, PHP, etc. Ruby on Rails is a popular web framework written in Ruby. This guide covers how to deploy Rails 6 apps to Heroku.


1 Answers

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.

like image 122
Michael van Rooijen Avatar answered Sep 18 '22 04:09

Michael van Rooijen