The Source for Java Technology Collaboration
User: Password:
Register | Login help    

Search

Online Books:
java.net on MarkMail:


Merb on JRuby 1.1 RC3

Posted by arungupta on April 3, 2008 at 5:51 AM PDT

This blog provides how you can get started with Merb on JRuby 1.1 RC3.

Merb is another MVC framework (just like Rails) but with a pluggable ORM, JavaScript library and Template language. Rails has built-in support for these using ActiveRecord, Script.aculo.us and ERB templates. Making it pluggable keeps the core very lightweight and still providing support for a particular feature using plugins. Another big advantage of Merb is that unlike Rails it's thread-safe.

There are already third party supports for ActiveRecord, DataMapper and Sequel ORMs. I will hopefully be able to build support for Java Persistence API ORM in Merb. Until then, here is how you install and get started with Merb on JRuby 1.1 RC3.

Install Merb on JRuby as:
Macintosh-187:jruby-1.1RC3 arungupta$ bin/jruby -S gem install merb mongrel
JRuby limited openssl loaded. gem install jruby-openssl for full support.
http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
Updating metadata for 339 gems from http://gems.rubyforge.org
.........................................................................................................
.........................................................................................................
.........................................................................................................
........................
complete
Successfully installed abstract-1.0.0
Successfully installed erubis-2.5.0
Successfully installed json_pure-1.1.2
Successfully installed rack-0.3.0
Successfully installed hpricot-0.6-java
Successfully installed mime-types-1.15
Successfully installed merb-core-0.9.2
Successfully installed merb-action-args-0.9.2
Successfully installed merb-assets-0.9.2
Successfully installed activesupport-2.0.2
Successfully installed rubigen-1.2.4
Successfully installed merb-gen-0.9.2
Successfully installed merb-haml-0.9.2
Successfully installed merb-builder-0.9.2
Successfully installed mailfactory-1.2.3
Successfully installed merb-mailer-0.9.2
Successfully installed merb-parts-0.9.2
Successfully installed merb-cache-0.9.2
Successfully installed merb-more-0.9.2
Successfully installed merb-0.9.2
Successfully installed gem_plugin-0.2.3
Successfully installed mongrel-1.1.4-java
22 gems installed
Installing ri documentation for json_pure-1.1.2...
Installing ri documentation for rack-0.3.0...
Installing ri documentation for hpricot-0.6-java...
Installing ri documentation for mime-types-1.15...
Installing ri documentation for merb-core-0.9.2...
Installing ri documentation for merb-action-args-0.9.2...
Installing ri documentation for merb-assets-0.9.2...
Installing ri documentation for activesupport-2.0.2...
Installing ri documentation for rubigen-1.2.4...
Installing ri documentation for merb-gen-0.9.2...
Installing ri documentation for merb-haml-0.9.2...
Installing ri documentation for merb-builder-0.9.2...
Installing ri documentation for mailfactory-1.2.3...
Installing ri documentation for merb-mailer-0.9.2...
Installing ri documentation for merb-parts-0.9.2...
Installing ri documentation for merb-cache-0.9.2...
Installing ri documentation for gem_plugin-0.2.3...
Installing ri documentation for mongrel-1.1.4-java...
Installing RDoc documentation for json_pure-1.1.2...
Installing RDoc documentation for rack-0.3.0...
Installing RDoc documentation for hpricot-0.6-java...
Installing RDoc documentation for mime-types-1.15...
Installing RDoc documentation for merb-core-0.9.2...
Installing RDoc documentation for merb-action-args-0.9.2...
Installing RDoc documentation for merb-assets-0.9.2...
Installing RDoc documentation for activesupport-2.0.2...
Installing RDoc documentation for rubigen-1.2.4...
Installing RDoc documentation for merb-gen-0.9.2...
Installing RDoc documentation for merb-haml-0.9.2...
Installing RDoc documentation for merb-builder-0.9.2...
Installing RDoc documentation for mailfactory-1.2.3...
Installing RDoc documentation for merb-mailer-0.9.2...
Installing RDoc documentation for merb-parts-0.9.2...
Installing RDoc documentation for merb-cache-0.9.2...
Installing RDoc documentation for gem_plugin-0.2.3...
Installing RDoc documentation for mongrel-1.1.4-java...
This is so much simpler than couple of weeks ago where all the dependencies had to be explicitly installed. Now create a sample application as:

Macintosh-187:jruby-1.1RC3 arungupta$ cd samples/
Macintosh-187:samples arungupta$ mkdir merb
Macintosh-187:samples arungupta$ cd merb/
Macintosh-187:merb arungupta$ ../../bin/jruby -S merb-gen app hello
RubiGen::Scripts::Generate
      create  app
      create  autotest
      create  config
      create  public
      create  spec
      create  app/controllers
      create  app/helpers
      create  app/views
      create  app/views/exceptions
      create  app/views/layout
      create  config/environments
      create  public/images
      create  public/stylesheets
      create  autotest/discover.rb
      create  autotest/merb.rb
      create  autotest/merb_rspec.rb
      create  config/rack.rb
      create  config/router.rb
      create  config/init.rb
      create  public/merb.fcgi
      create  spec/spec.opts
      create  spec/spec_helper.rb
      create  app/controllers/application.rb
      create  app/controllers/exceptions.rb
      create  app/helpers/global_helpers.rb
      create  app/views/exceptions/internal_server_error.html.erb
      create  app/views/exceptions/not_acceptable.html.erb
      create  app/views/exceptions/not_found.html.erb
      create  app/views/layout/application.html.erb
      create  config/environments/development.rb
      create  config/environments/production.rb
      create  config/environments/rake.rb
      create  config/environments/test.rb
      create  public/images/merb.jpg
      create  public/stylesheets/master.css
      create  /Rakefile

The top-level directory looks like:

Macintosh-187:hello arungupta$ ls -la
total 8
drwxr-xr-x  8 arungupta  arungupta   272 Apr  1 22:20 .
drwxr-xr-x  3 arungupta  arungupta   102 Apr  1 22:20 ..
-rw-r--r--  1 arungupta  arungupta  3334 Apr  1 22:20 Rakefile
drwxr-xr-x  5 arungupta  arungupta   170 Apr  1 22:20 app
drwxr-xr-x  5 arungupta  arungupta   170 Apr  1 22:20 autotest
drwxr-xr-x  6 arungupta  arungupta   204 Apr  1 22:20 config
drwxr-xr-x  5 arungupta  arungupta   170 Apr  1 22:20 public
drwxr-xr-x  4 arungupta  arungupta   136 Apr  1 22:20 spec

And finally start the app as:

Macintosh-187:hello arungupta$ ../../../bin/jruby -S merb
JRuby limited openssl loaded. gem install jruby-openssl for full support.
http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
 ~ Loaded DEVELOPMENT Environment...
 ~ Compiling routes...
 ~ Using 'share-nothing' cookie sessions (4kb limit per client)
 ~ Using Mongrel adapter

And the default app is hosted at "http://localhost:4000/" and shown in the browser as:

There is a wealth of information available to get you going after this. Here are couple of things to try:
  • If possible, use WARbler to package Merb app and deploy on GlassFish.
  • Try Java Persistence API as the pluggable ORM.

Technorati: rubyonrails merb jruby ruby jpa glassfish
Related Topics >> Web Applications      
Comments
Comments are listed in date ascending order (oldest first)