Upgrade to Pro — share decks privately, control downloads, hide ads and more …

JRuby - How Java and Ruby meet on the JVM, PolyConf 2015

JRuby - How Java and Ruby meet on the JVM, PolyConf 2015

Slides from the talk at PolyConf
Poznan, Poland
July 2015

Alissa Bonas

July 03, 2015
Tweet

More Decks by Alissa Bonas

Other Decks in Programming

Transcript

  1. Some JRuby facts • Exists since 2001 • Can run

    Ruby on Rails apps since 2006 • Tightly integrated with Java
  2. Versions support • Jruby 1.7.x ◦ Supports Ruby 1.9.3 ◦

    Experimental Ruby 2.0 support • Jruby 9.0.0.0 - in the works ◦ Supports Ruby 2.2
  3. Why

  4. Reasons to use JRuby • Integrate Java and Ruby projects

    • Enjoy libraries in both languages • Bonus ◦ Multithreading ◦ Packaging
  5. Multithreading • Green threads vs native threads ◦ GIL (global

    interpreter lock) • One process instead of multiple
  6. How

  7. Java Calling Ruby • Eval of Ruby code • Sharing

    variables with a Ruby script • Reading the return value
  8. Java Calling Ruby • JRuby Embed (aka Red Bridge) ◦

    Embed core ◦ JSR 223 - Java’s scripting engine ◦ BSF (Bean Scripting Framework) • No need to compile Ruby into bytecode
  9. JRuby Embed core • Add jruby.jar to your Java project

    • specify JRUBY_HOME ◦ needed if JRuby installed via RVM
  10. Ruby script example # GET http://10.35.0.23:8080/api require ‘net/http’ endpoint =

    URI::HTTP.build(:host => @host, :port => @port) endpoint.path = ‘/api’ request = Net::HTTP::Get.new(endpoint.to_s) resp = Net::HTTP.start(endpoint.host, endpoint.port) { | http | http.request(request) } resp.body
  11. Example of Rails with JRuby • Open source Java project

    - Spago BI • Several Java reports engines • Adding a Ruby on Rails reports engine
  12. Reports Engine 1 Reports Engine 2 Reports Engine 3 UI

    Reports Engine 4 http /engine1 http /engine2 http /engine3 http /engine4 SOA Tomcat SOA SOA SOA SOA
  13. Database drivers • JDBC drivers • Specify them in Gemfile

    • Specify them in config/database.yml
  14. Packaging • Use Warbler • Create a .war file •

    Flexible configuration possibilities ◦ option to precompile the classes - avoid surprise in production
  15. Credits and sources • Tomcat-logo by The Apache Tomcat Project

    Team • Mug by Alex Getty from the Noun Project • Diamond by MarkieAnn Packer from the Noun Project • Box by Cornelius Danger from the Noun Project • Clapperboard by Edgar Vargas from the Noun Project • Questions by Rediffusion from the Noun Project • Rails by Luis Martins from the Noun Project