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.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Introduction to JRuby And JRuby on Rails

361
views

Published on

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
361
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 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: http://jruby.org/download - Instructions: https://github.com/jruby/jruby/wiki/GettingStarted - 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 = ArrayList.new frame = javax.swing.JFrame.new("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 = JavaLang::String.new("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 = Hello.new 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 http://jruby.org/rails3.rb • /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