Getting Started with
Rails on GlassFish
(Hands-on Lab)




Arun Gupta, Java EE & GlassFish Guy,
Oracle Corp
blogs.sun.com/...
What this session is not ?

• Not a GlassFish tutorial
• Not a Rails tutorial
• Not a MySQL tutorial
Software Installed ?

• JDK 1.6.0_XX
• NetBeans 6.8 (“All” or “Ruby” bundle)
• JRuby 1.4.0
• MySQL Community Server




  ...
What is GlassFish ?
What is GlassFish ?
GlassFish: It's a Community!
GlassFish: Lives on java.net




   Since 2005
GlassFish: Open Source and
Production Quality
GlassFish: Reference Implementation



          Java EE 5
          Java EE 6
GlassFish v3
What is Ruby-on-Rails ?

• Full-stack Web development framework in
 Ruby
 • Popularly known as Rails
• Current Version: Ra...
Ruby-on-Rails MVC
                                  Incoming
                                  Request



                ...
Rails Design Principles

• Convention over Configuration (CoC)
  • Common cases easily served
  • Encourages standard prac...
JRuby
• Ruby interpreter written in Java
• Current Version: 1.4.0
  • 1.5 RC coming soon
• Ruby 1.8.7 compatible
• Some Ru...
JRuby
• Solid performance ( ͋Ruby 1.9)
  • Startup is poor, execution usually better than
    1.9
• Runs native threads
• ...
Install JRuby

• CLI: Download & Unzip “jruby-
 bin-1.4.0.zip” from jruby.org

• NetBeans “All” or “Ruby” bundle
 (pre-ins...
Install Rails & GlassFish Gem

• CLI: “jruby -S gem install rails
 glassfish”

• NetBeans: Tools -> Ruby Gems
 -> New Gems...
Start Database

• Mac/Linux: mysqld_safe --user
root

• Windows: bin/mysqld-nt --user
root
 • Installed as service ?
     ...
Install Database Adapter


“jruby -S gem install
activerecord-jdbcmysql-adapter”




                            2 minutes
Create a Rails App


jruby -S rails helloworld -d mysql
cd helloworld
jruby script/generate jdbc
jruby -S rake db:create

...
Run the App

cd helloworld
jruby -S glassfish




                     5 minutes
Add CRUD features

jruby script/generate scaffold
   book title:string author:string




                            5 min...
Model View Controller
      exists app/models/
      exists app/controllers/
      exists app/helpers/
      create app/vi...
Generate Database Table

   jruby -S rake db:migrate

== CreateBooks: migrating ============================
-- create_tab...
Sample Output




                5 minutes
GlassFish Gem




 http://rubyforge.org/projects/glassfishgem/
GlassFish Gem: Options


 jruby -S glassfish -h

 -c: change the context root
 -e: environment
 -d: runs as daemon
 -P: lo...
GlassFish Gem: Recipes
Why Rails on GlassFish ? - Agile
Why ? - Easy prototyping, yet powerful
Why ? - Best of both worlds
Why ? - Database Connection Pooling
Why ? - Management
Why ? - Monitoring
Directory-based deployment: How ?


asadmin start-domain
asadmin deploy
   --property "jruby.home=JRUBY_HOME"
   helloworl...
Directory-based deployment: Recipes
Not Just Rails ...




http://blogs.sun.com/arungupta/entry/totd_53_scaffold_in_merb
http://blogs.sun.com/arungupta/entry/...
And more ...




http://weblogs.java.net/blog/vivekp/archive/2009/04/plugin_any_ruby.html
Deployment Options




http://blogs.sun.com/arungupta/entry/totd_81_how_to_use
http://blog.headius.com/2009/04/apache-jrub...
Rails on GlassFish: WAR Deployment
WAR Deployment: How ?




 jruby -S gem install warbler
 jruby -S warble
 asadmin deploy xxx.war


                       ...
WAR Deployment: How in NetBeans ?
WAR Deployment: Packaging
Rails on GlassFish: Update Center
NetBeans: Develop with Pleasure




                                                     10 minutes
http://blogs.sun.com/a...
Rails Monitoring

• Basic Monitoring
 •   jinfo: System properties and VM CLI flags
 •   jmap: Shared object memory map
 •...
jConsole




      http://blogs.sun.com/arungupta/tags/rubyonrails+jmx
Turbo charging your JRuby Startup

• “-client” or “-server” ? (Upto 50%)
   • Faster startup or solid runtime ?
   • expor...
Who loves Rails on GlassFish ?
Resources

• glassfish.org
• blogs.sun.com/theaquarium
• glassfish-scripting.dev.java.net
• wiki.glassfish.java.net/Wiki.j...
Getting Started with Rails on GlassFish (Hands-on Lab) - Spark IT 2010
Getting Started with Rails on GlassFish (Hands-on Lab) - Spark IT 2010
Getting Started with Rails on GlassFish (Hands-on Lab) - Spark IT 2010
Getting Started with Rails on GlassFish (Hands-on Lab) - Spark IT 2010
Getting Started with Rails on GlassFish (Hands-on Lab) - Spark IT 2010
Getting Started with Rails on GlassFish (Hands-on Lab) - Spark IT 2010
Getting Started with Rails on GlassFish (Hands-on Lab) - Spark IT 2010
Upcoming SlideShare
Loading in...5
×

Getting Started with Rails on GlassFish (Hands-on Lab) - Spark IT 2010

2,695

Published on

Getting Started with Rails on GlassFish (Hands-on Lab) - Spark IT 2010

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
2,695
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
32
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Getting Started with Rails on GlassFish (Hands-on Lab) - Spark IT 2010

  1. 1. Getting Started with Rails on GlassFish (Hands-on Lab) Arun Gupta, Java EE & GlassFish Guy, Oracle Corp blogs.sun.com/arungupta, @arungupta
  2. 2. What this session is not ? • Not a GlassFish tutorial • Not a Rails tutorial • Not a MySQL tutorial
  3. 3. Software Installed ? • JDK 1.6.0_XX • NetBeans 6.8 (“All” or “Ruby” bundle) • JRuby 1.4.0 • MySQL Community Server 15 minutes
  4. 4. What is GlassFish ?
  5. 5. What is GlassFish ?
  6. 6. GlassFish: It's a Community!
  7. 7. GlassFish: Lives on java.net Since 2005
  8. 8. GlassFish: Open Source and Production Quality
  9. 9. GlassFish: Reference Implementation Java EE 5 Java EE 6
  10. 10. GlassFish v3
  11. 11. What is Ruby-on-Rails ? • Full-stack Web development framework in Ruby • Popularly known as Rails • Current Version: Rails 2.3.5 • Rails 3.0 coming
  12. 12. Ruby-on-Rails MVC Incoming Request Web Server ActionController (Controller) ActiveRecord ActionView xxx_controller.rb (Model) (View) xxx.rb .rhtml .erb Database
  13. 13. Rails Design Principles • Convention over Configuration (CoC) • Common cases easily served • Encourages standard practices • Everything simpler and smaller • Don't Repeat Yourself (DRY) • Framework written around minimizing repetition • Agile Development • No compile, redeploy, restart cycles • Testing built into the framework
  14. 14. JRuby • Ruby interpreter written in Java • Current Version: 1.4.0 • 1.5 RC coming soon • Ruby 1.8.7 compatible • Some Ruby 1.9 support • --1.9 flag (80%)
  15. 15. JRuby • Solid performance ( ͋Ruby 1.9) • Startup is poor, execution usually better than 1.9 • Runs native threads • Foreign Function Interface (FFI)for C libraries • Adopted from Rubinius, CRuby gem • Runs Rails great!
  16. 16. Install JRuby • CLI: Download & Unzip “jruby- bin-1.4.0.zip” from jruby.org • NetBeans “All” or “Ruby” bundle (pre-installed)
  17. 17. Install Rails & GlassFish Gem • CLI: “jruby -S gem install rails glassfish” • NetBeans: Tools -> Ruby Gems -> New Gems • Rails pre-installed • Search “glassfish”, Install 5 minutes
  18. 18. Start Database • Mac/Linux: mysqld_safe --user root • Windows: bin/mysqld-nt --user root • Installed as service ? 2 minutes
  19. 19. Install Database Adapter “jruby -S gem install activerecord-jdbcmysql-adapter” 2 minutes
  20. 20. Create a Rails App jruby -S rails helloworld -d mysql cd helloworld jruby script/generate jdbc jruby -S rake db:create 5 minutes
  21. 21. Run the App cd helloworld jruby -S glassfish 5 minutes
  22. 22. Add CRUD features jruby script/generate scaffold book title:string author:string 5 minutes
  23. 23. Model View Controller exists app/models/ exists app/controllers/ exists app/helpers/ create app/views/books exists app/views/layouts/ exists test/functional/ exists test/unit/ create test/unit/helpers/ exists public/stylesheets/ create app/views/books/index.html.erb create app/views/books/show.html.erb create app/views/books/new.html.erb create app/views/books/edit.html.erb create app/views/layouts/books.html.erb create public/stylesheets/scaffold.css create app/controllers/books_controller.rb create test/functional/books_controller_test.rb create app/helpers/books_helper.rb create test/unit/helpers/books_helper_test.rb route map.resources :books dependency model exists app/models/ exists test/unit/ exists test/fixtures/ create app/models/book.rb create test/unit/book_test.rb create test/fixtures/books.yml create db/migrate create db/migrate/20100310221044_create_books.rb
  24. 24. Generate Database Table jruby -S rake db:migrate == CreateBooks: migrating ============================ -- create_table(:books) -> 0.1690s -> 0 rows == CreateBooks: migrated (0.1710s) ===================== 2 minutes
  25. 25. Sample Output 5 minutes
  26. 26. GlassFish Gem http://rubyforge.org/projects/glassfishgem/
  27. 27. GlassFish Gem: Options jruby -S glassfish -h -c: change the context root -e: environment -d: runs as daemon -P: location of PID file -l: log file location -log-level: Logging level (0-7)
  28. 28. GlassFish Gem: Recipes
  29. 29. Why Rails on GlassFish ? - Agile
  30. 30. Why ? - Easy prototyping, yet powerful
  31. 31. Why ? - Best of both worlds
  32. 32. Why ? - Database Connection Pooling
  33. 33. Why ? - Management
  34. 34. Why ? - Monitoring
  35. 35. Directory-based deployment: How ? asadmin start-domain asadmin deploy --property "jruby.home=JRUBY_HOME" helloworld Complete Absolute Path 7 minutes
  36. 36. Directory-based deployment: Recipes
  37. 37. Not Just Rails ... http://blogs.sun.com/arungupta/entry/totd_53_scaffold_in_merb http://blogs.sun.com/arungupta/entry/totd_80_sinatra_crud_application
  38. 38. And more ... http://weblogs.java.net/blog/vivekp/archive/2009/04/plugin_any_ruby.html
  39. 39. Deployment Options http://blogs.sun.com/arungupta/entry/totd_81_how_to_use http://blog.headius.com/2009/04/apache-jruby-rails-glassfish-easy.html
  40. 40. Rails on GlassFish: WAR Deployment
  41. 41. WAR Deployment: How ? jruby -S gem install warbler jruby -S warble asadmin deploy xxx.war 7 minutes http://blogs.sun.com/arungupta/entry/totd_73_jruby_and_glassfish
  42. 42. WAR Deployment: How in NetBeans ?
  43. 43. WAR Deployment: Packaging
  44. 44. Rails on GlassFish: Update Center
  45. 45. NetBeans: Develop with Pleasure 10 minutes http://blogs.sun.com/arungupta/entry/screencast_26_develop_run_debug
  46. 46. Rails Monitoring • Basic Monitoring • jinfo: System properties and VM CLI flags • jmap: Shared object memory map • jstack: Stack traces of Java threads • jstat: Performance statistics on class, JIT compiler, GC, ... • Advanced • jconsole / Visual VM • NewRelic, FiveRuns, ...
  47. 47. jConsole http://blogs.sun.com/arungupta/tags/rubyonrails+jmx
  48. 48. Turbo charging your JRuby Startup • “-client” or “-server” ? (Upto 50%) • Faster startup or solid runtime ? • export JAVA_OPTS=”-client -D32” • Upto 50% improvement • For Linux: Class Data Sharing • Delay or disable JRuby's JIT (Upto 10%) • -X-C • jruby.compile.mode=OFF • Avoid spawning “sub-Rubies” • Nailgun for small JRuby CLI invocations • Favorite JVM Flags
  49. 49. Who loves Rails on GlassFish ?
  50. 50. Resources • glassfish.org • blogs.sun.com/theaquarium • glassfish-scripting.dev.java.net • wiki.glassfish.java.net/Wiki.jsp? page=JRuby • blogs.sun.com/arungupta
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×