如何在 Heroku 上部署 JRuby Rails 3.1.x?

发布于 2024-12-17 02:45:28 字数 3114 浏览 2 评论 0原文

我希望能够将 jruby Rails 3.1 应用程序部署到 Heroku。

Heroku 现在支持 Java:http://blog.heroku.com/archives/2011/08/25/ java/ 据说,应该可以部署 JRuby Rails 应用程序。 这里有一个关于普通 java 的教程:http://devcenter.heroku.com/articles/java 和另一个这里:< a href="http://devcenter.heroku.com/articles/spring-mvc-hibernate">http://devcenter.heroku.com/articles/spring-mvc-hibernate

这是 JRuby 的教程Heroku 上的 Sinatra 应用程序: http://chris.chowie.net/2011/08/28/Sinatra -with-JRuby-on-Heroku/ 为了让它工作,我在运行heroku时使用非jruby ruby​​,因为如果rvm使用jruby,heroku会崩溃。

为了运行命令,

mvn package

我必须运行以下命令:

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

我创建了应用程序:

heroku create jg1-sinatra --stack cedar

我将文件推送到heroku,但是当应用程序启动时,它崩溃了。 :(

有什么建议吗?我猜不久之后 Heroku 就会有这方面的教程。

来自 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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

念三年u 2024-12-24 02:45:28

从 Bundler 1.2 开始,您现在可以在 指定 Ruby 实现和版本 >宝石文件。这样做的好处是 Heroku 会理解这些设置并为您的环境准备 Heroku 应用程序。

以这个 Gemfile 为例:

source "https://rubygems.org"

ruby "1.9.3"

gem "rails"
gem "puma"

这个很酷的是,Celadon Cedar 默认使用 Ruby 1.9.2。但是,当您在 Gemfile 中指定 ruby "1.9.3" 时,它实际上会为您的 Heroku 环境编译 Ruby 1.9.3。

现在,如果您想向您的 Heroku 环境添加不同的 Ruby 实现,您可以这样做:

source "https://rubygems.org"

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

gem "rails"
gem "puma"

现在,它将在部署时为您的 Heroku 应用程序安装并使用 Ruby 1.9 模式下的 JRuby 1.7.0.preview1。它甚至还会在 Heroku 环境变量中定义正确的 JVM 选项。

最重要的是,它附带了官方 Heroku buildpack,因此无需切换到第 3 方构建包以使 JRuby/JVM 在 Heroku 上运行。虽然我还没有让它工作,但这个 也应该与 Rubinius 一起使用,但我相信它目前已被窃听。要么是这样,要么我做错了。

在我看来,这是一个很棒且可扩展的功能。只需定义您在 Gemfile 中使用的 Ruby 实现/版本/模式以及其他依赖项,Heroku 将确保环境准备就绪。

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.

仙气飘飘 2024-12-24 02:45:28

你有这一行:

Classpath is: :/app/etc:/.m2/repository/org/jruby/jruby-complete/1.6.3/jruby-complete-1.6.3.jar

接缝你在某处引用了你的语言环境存储库,而科西嘉岛的 Heroku 没有它。
我对包装不太了解,但这个参考可能会出现在这里吗?

检查所有参考并查看包装选项可能是一个好的开始......

You have this line :

Classpath is: :/app/etc:/.m2/repository/org/jruby/jruby-complete/1.6.3/jruby-complete-1.6.3.jar

Seams you have reference to your locale repository somewhere and Heroku of corse don't have it.
I dunno so much about packaging, but may be this reference appear here ?

Check all ref and see packaging options could be a good start ...

香橙ぽ 2024-12-24 02:45:28

随着第三方构建包的出现,以前在 Heroku 上获取 JRuby 和其他不受支持的运行时的技巧现已过时:

https://devcenter.heroku.com/articles/buildpacks
https://github.com/jruby/heroku-buildpack-jruby

Previous hacks for getting JRuby and other non-supported runtimes on Heroku are now obsolete with the availability of third-party buildpacks:

https://devcenter.heroku.com/articles/buildpacks
https://github.com/jruby/heroku-buildpack-jruby

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文