View
2.723
Download
1
Category
Tags:
Preview:
DESCRIPTION
Getting Started with Rails on GlassFish (Hands-on Lab) - Spark IT 2010
Citation preview
Getting Started withRails on GlassFish(Hands-on Lab)
Arun Gupta, Java EE & GlassFish Guy,Oracle Corpblogs.sun.com/arungupta, @arungupta
Software Installed ?
• JDK 1.6.0_XX• NetBeans 6.8 (“All” or “Ruby” bundle)• JRuby 1.4.0• MySQL Community Server
15 minutes
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
Ruby-on-Rails MVC
Web Server
ActionController(Controller)
ActiveRecord(Model)
ActionView(View)
Database
xxx_controller.rb
.rhtml .erbxxx.rb
IncomingRequest
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
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%)
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!
Install JRuby
• CLI: Download & Unzip “jruby-bin-1.4.0.zip” from jruby.org
• NetBeans “All” or “Ruby” bundle (pre-installed)
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
Start Database
• Mac/Linux: mysqld_safe --user root
• Windows: bin/mysqld-nt --user root• Installed as service ?
2 minutes
Create a Rails App
jruby -S rails helloworld -d mysqlcd helloworldjruby script/generate jdbcjruby -S rake db:create
5 minutes
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
Generate Database Table
jruby -S rake db:migrate
== CreateBooks: migrating ============================-- create_table(:books) -> 0.1690s -> 0 rows== CreateBooks: migrated (0.1710s) =====================
2 minutes
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)
Directory-based deployment: How ?
asadmin start-domainasadmin deploy --property "jruby.home=JRUBY_HOME" helloworld
CompleteAbsolute
Path
7 minutes
Not Just Rails ...
http://blogs.sun.com/arungupta/entry/totd_53_scaffold_in_merbhttp://blogs.sun.com/arungupta/entry/totd_80_sinatra_crud_application
Deployment Options
http://blogs.sun.com/arungupta/entry/totd_81_how_to_usehttp://blog.headius.com/2009/04/apache-jruby-rails-glassfish-easy.html
WAR Deployment: How ?
jruby -S gem install warblerjruby -S warbleasadmin deploy xxx.war
http://blogs.sun.com/arungupta/entry/totd_73_jruby_and_glassfish7 minutes
NetBeans: Develop with Pleasure
http://blogs.sun.com/arungupta/entry/screencast_26_develop_run_debug
10 minutes
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, ...
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
Recommended