Your SlideShare is downloading. ×
Introduction to JRuby And JRuby on Rails
Upcoming SlideShare
Loading in...5

Thanks for flagging this SlideShare!

Oops! An error has occurred.


Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Introduction to JRuby And JRuby on Rails


Published on

Published in: Technology

  • Be the first to comment

  • Be the first to like this

No Downloads
Total Views
On Slideshare
From Embeds
Number of Embeds
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

No notes for slide


  • 1. Introduction to JRuby Design by Mr.Huân
  • 2. What is JRuby?  JRuby is an implementation of Ruby programming language that runs on the Java Virtual Machine(JVM).  Started in 2002, open source, many contributors.  Releases > June 2007: 1.0 release, focus on compatibility. > April 2008: 1.1 release, focus on performance.  Aiming for compatibility with current Ruby version. > JRuby 1.7.6 is compatible with: Ruby 1.9.3
  • 3. Why Use JRuby? • With JRuby you get the best of both worlds: Ruby applications and libraries,plus Java libraries. And you can access those libraries with Ruby syntax (or Java syntax, if you want). • On average JRuby, runs 2 and a half times faster than Ruby, except at startup. • In addition to native threads, JRuby supports Unicode Natively. • Code can be fully compiled ahead of time or just in time.
  • 4. Install JRuby and JRuby Gems • Download and install JRuby - Download: - Instructions: - In linux : rvm install jruby or rbenv install jruby • Install JRuby Gems: - jruby -S gem install rails mongrel
  • 5. Calling Java From JRuby include Java & import: include Java statement will give you access to the bundled Java libraries. However, this will not give you access to non-bundled libraries.  • The import statement is used to import a Java Class. include Java import java.util.ArrayList import javax.swing.JFrame list = frame ="Passion!") list << frame list.each {|f| f.set_size(200,200) }
  • 6. Calling Java From JRuby (cont) include_package within a JRuby Module: • Use include_package"<package_name>"in a JRuby Module to support namespaced access to the Java classes in the package. include Java module JavaLang include_package "java.lang" end s ="This is my string from java.lang package")
  • 7. Calling Java From JRuby (cont) include_class: • Use include_class "<class_name>" to include unbundled Java classes. • The unbundled Java classes(in the form of jar file) should be in the classpath. include Java include_class 'mypackage.Hello' h = puts "----Invoke a method of from Hello object" s = h.sayHello("Message from Hello Java Class!")
  • 8. JRuby on Rails You can use JRuby with Ruby on Rails. JRuby gives Rails the power and functionality of the Java Platform, providing it with: • Excellent garbage collection for endless uptimes. • Hotspot profiled dynamic optimizations for great performance. • Access to the Java ecosphere for additional technology options. • Deployment to Java application servers for ubiquity.
  • 9. JRuby on Rails • Create a new JRuby on Rails app: - gem install rails - rails new blog - rails new my_app -m • /Gemfile - gem 'activerecord-jdbcsqlite3-adapter‘ - gem 'jruby-openssl' - gem 'therubyrhino'
  • 10. Deployment •  Use JRuby, you can use a Java application servers:  Tomcat , Glassfish, Jetty, Jboss… • To deploy to a Java app server, you can use the tool  Warbler to bundle your Rails application in a Java Web  Application Archive. • Once you have a .war file, you can deploy to any Java  app server using its war deployment mechanism
  • 11. Demo
  • 12. Thank for watching