SlideShare a Scribd company logo
JRuby and You
                                Hiro Asari
                                Engine Yard




Wednesday, October 26, 11
History
                      September 10, 2001




                            Source: Wikipedia



Wednesday, October 26, 11
Wednesday, October 26, 11
Project Status


                    • Current stable release: 1.6.5 (Oct 25, 2011)
                    • Rails 3.1-compatible


Wednesday, October 26, 11
What’s next in 1.7?


                    • JSR 292 (a.k.a. invokedynamic) support
                    • Improved Ruby 1.9 support


Wednesday, October 26, 11
What’s in it for Java
                             programmers?

                    • REPL
                    • Testing frameworks
                    • Fun


Wednesday, October 26, 11
What’s in it for
                             Rubyists?
                    • Real threads
                    • No more GIL
                    • Mature garbage collector
                    • Easy deployment

Wednesday, October 26, 11
Try JRuby
                            http://jruby.org/tryjruby




Wednesday, October 26, 11
Getting JRuby

        wget http://bit.ly/jruby_bin_165 | 
        tar xzvf -

        export PATH=$PATH:$PWD/jruby-1.6.5/bin




Wednesday, October 26, 11
jruby -S irb
Wednesday, October 26, 11
Java Integration

                              require 'java'




Wednesday, October 26, 11
Loading JAR

                            require 'example.jar'




Wednesday, October 26, 11
Importing Java Class

      StringBuffer = java.lang.StringBuffer
      sb = StringBuffer.new "foo"




Wednesday, October 26, 11
java_import

        java_import java.lang.StringBuffer
        java_import 'java.lang.StringBuffer'




Wednesday, October 26, 11
Static methods

        java.lang.System.currentTimeMillis
        java.lang.System.current_time_millis




Wednesday, October 26, 11
Static Fields

        java_import java.util.logging.Logger
        java_import java.util.loggin.Level

        Logger.global.log Level::SEVERE, "…"




Wednesday, October 26, 11
Constructor

      URL.new 'http://engineyard.com'
      URL.new 'http', 'engineyard.com', '/'




Wednesday, October 26, 11
Instance methods
                            #given
                            # void setPrice(int):
                            car.setPrice(2000)
                            car.price = 2000

                            # int getPrice()
                            car.price




Wednesday, October 26, 11
Explicit Coercion

                             measurement = 5
                             measurement.to_java




Wednesday, October 26, 11
Overloaded methods
       public class C {
         public static String method(String s) {
           return "String";
         }
         public static String method(long l) {
           return "long";
         }
       }




Wednesday, October 26, 11
Overloaded methods


      obj = C.new
      obj.method("foo") # => "String"
      obj.method(5) # => "long"




Wednesday, October 26, 11
Overloaded methods
                public class C {
                  public String method(int i) {
                    return "int";
                  }
                  public String method(long l) {
                    return "long";
                  }
                }


Wednesday, October 26, 11
Overloaded methods

      obj = C.new
      obj.method(5) # => "long"
      obj.method(5.to_java(Java::int))
      obj.java_send :method, [Java::int], 5




Wednesday, October 26, 11
Java Interfaces

      callable =
      java.util.concurrent.Executors.callable do
        puts "foo"
      end

      callable.call




Wednesday, October 26, 11
Complex Example with
                        Akka
                       Java source: http://bit.ly/lTClmr
                       Ruby source: https://gist.github.com/1013227
                       http://www.engineyard.com/blog/2011/using-
                       java-from-ruby-with-jruby-irb/




Wednesday, October 26, 11
GUI

               Redcar

 http://redcareditor.com/




Wednesday, October 26, 11
Grafting Rails into
                              Spring MVC




Wednesday, October 26, 11
Pet Clinic

                                    • Example
                                         database-
                                         backed web
                                         app for
                                         Spring
                                         framework


Wednesday, October 26, 11
Requests


                                                 JRuby

                            /   /vets   /rack/   Java/
                                                 Spring

                                App
Wednesday, October 26, 11
Adding Route
   diff --git a/src/main/webapp/WEB-INF/jsp/vets.jsp b/src/main/webapp/WEB-INF/jsp/vets.jsp
   index cff2154..0d99817 100644
   --- a/src/main/webapp/WEB-INF/jsp/vets.jsp
   +++ b/src/main/webapp/WEB-INF/jsp/vets.jsp
   @@ -23,7 +23,7 @@
     <table class="table-buttons">
       <tr>
         <td>
   -        <a href="<spring:url value="/vets.xml" htmlEscape="true" />">View as XML</a>
   +        <a href="<spring:url value="/rack/vets.xml" htmlEscape="true" />">View as XML</a>
         </td>
       </tr>
     </table>




Wednesday, October 26, 11
Cucumber


                    • http://cukes.info
                    • Testing framework for describing software
                            behavior in plain English




Wednesday, October 26, 11
Cucumber
         Feature: Pets

                Scenario: Edit Pet
                  Given I am on the owners search page
                  And I press "Find Owners"
                  And I follow "George Franklin"
                  And I follow "Edit Pet"
                  When I fill in "Name" with "Leoni"
                  And press "Update Pet"
                  Then I should see "Leoni"



Wednesday, October 26, 11
Cucumber test
          Stand by while Tomcat finishes booting...
          Using the default profile...
          ............................................................F-.............

          (::) failed steps (::)

          expected: /xml/,
                got: "text/html;charset=utf-8" (using =~)
          Diff:
          @@ -1,2 +1,2 @@
          -/xml/
          +text/html;charset=utf-8
           (RSpec::Expectations::ExpectationNotMetError)
          org/jruby/RubyProc.java:268:in `call'
          ./features/step_definitions/xml_json_steps.rb:12:in `(root)':in `/^I should see
          an XML document$/'
          features/vets.feature:6:in `Then I should see an XML document'

          Failing Scenarios:
          cucumber features/vets.feature:3 # Scenario: View vets as XML

          13 scenarios (1 failed, 12 passed)
          75 steps (1 failed, 1 skipped, 73 passed)
          0m7.709s
          rake aborted!
          Cucumber failed



Wednesday, October 26, 11
diff --git a/pom.xml b/pom.xml
                            index 9e22f83..0810701 100644
                            --- a/pom.xml
                            +++ b/pom.xml
                            @@ -211,6 +211,18 @@
                                                    <scope>provided</scope>
                                            </dependency>

                            +                <!-- JRuby and JRuby-Rack -->
                            +                <dependency>
                            +                        <groupId>org.jruby</groupId>
                            +                        <artifactId>jruby-complete</artifactId>
                            +                        <version>1.6.0</version>
                            +                </dependency>
                            +                <dependency>
                            +                        <groupId>org.jruby.rack</groupId>
                            +                        <artifactId>jruby-rack</artifactId>
                            +                        <version>1.0.8</version>
                            +                </dependency>
                            +
                                            <!-- Test dependencies -->
                                            <dependency>
                                                    <groupId>org.junit</groupId>




Wednesday, October 26, 11
diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml
    index 8d02684..60ed6cb 100644
    --- a/src/main/webapp/WEB-INF/web.xml
    +++ b/src/main/webapp/WEB-INF/web.xml
    @@ -87,6 +87,21 @@
            <listener>
                    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
            </listener>
    +
    +        <listener>
    +                <listener-class>org.jruby.rack.RackServletContextListener</listener-class>
    +        </listener>
    +
    +        <servlet>
    +                <servlet-name>rack</servlet-name>
    +                <servlet-class>org.jruby.rack.RackServlet</servlet-class>
    +        </servlet>
    +
    +        <servlet-mapping>
    +                <servlet-name>rack</servlet-name>
    +                <url-pattern>/rack/*</url-pattern>
    +        </servlet-mapping>
    +

                <!--
                            Defines the 'default' servlet (usually for service static resources).




Wednesday, October 26, 11
diff --git a/src/main/webapp/WEB-INF/lib/app.rb b/src/main/webapp/WEB-INF/lib/
                     app.rb
                     index 6ab5b3c..4398fb4 100644
                     --- a/src/main/webapp/WEB-INF/lib/app.rb
                     +++ b/src/main/webapp/WEB-INF/lib/app.rb
                     @@ -1,6 +1,33 @@
                       require 'builder'
                       require 'erb'
                     +require 'spring_helpers'
                     +
                     +helpers do
                     + include Spring
                     +end

                      get '/rack/' do
                        '<h1>Sinatra</h1>'
                      end
                     +
                     +get '/rack/vets.xml' do
                     + content_type 'application/vnd.petclinic+xml'
                     + builder do |xml|
                     +    xml.instruct!
                     +    xml.vets do
                     +      clinic.vets.each do |vet|
                     +        xml.vetList do
                     +          xml.id vet.id
                     +          xml.firstName vet.firstName
                     +          xml.lastName vet.lastName
                     +          vet.specialties.each do |spec|
                     +            xml.specialties do
                     +              xml.id spec.id
                     +              xml.name spec.name
                     +            end
                     +          end
                     +        end
                     +      end
                     +    end
                     + end
                     +end


Wednesday, October 26, 11
Requests



                      /     /vets                        JRuby

                                              /owners    Java/
                      /     /vets   /owners    /1/pets   Spring


                               App
Wednesday, October 26, 11
diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml
               index 60ed6cb..f64b34d 100644
               --- a/src/main/webapp/WEB-INF/web.xml
               +++ b/src/main/webapp/WEB-INF/web.xml
               @@ -92,16 +92,6 @@
                                <listener-class>org.jruby.rack.RackServletContextListener</listener-class>
                        </listener>

               -             <servlet>
               -                     <servlet-name>rack</servlet-name>
               -                     <servlet-class>org.jruby.rack.RackServlet</servlet-class>
               -             </servlet>
               -
               -             <servlet-mapping>
               -                     <servlet-name>rack</servlet-name>
               -                     <url-pattern>/rack/*</url-pattern>
               -             </servlet-mapping>
               -

                            <!--
                               Defines the 'default' servlet (usually for service static resources).
               @@ -162,6 +152,16 @@
                               <url-pattern>/</url-pattern>
                       </servlet-mapping>

               +             <filter>
               +                     <filter-name>RackFilter</filter-name>
               +                     <filter-class>org.jruby.rack.RubyFirstRackFilter</filter-class>
               +             </filter>
               +
               +             <filter-mapping>
               +                     <filter-name>RackFilter</filter-name>
               +                     <url-pattern>/*</url-pattern>
               +             </filter-mapping>
               +
                            <filter>
                                       <filter-name>httpMethodFilter</filter-name>
                                       <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>




Wednesday, October 26, 11
The Book

                      http://pragprog.com/book/
                      jruby/using-jruby

                      25% off for one week
                      only: http://bit.ly/vd4Mhj




Wednesday, October 26, 11
Engine Yard

                        500 free hours
                     http://engineyard.com




Wednesday, October 26, 11
Questions?
                        Twitter @hiro_asari
                     G+ http://gplus.to/hiroasari
               LinkedIn http://linkedin.com/in/hiroasari

                             asari.ruby@gmail.com
                            hasari@engineyard.com

                        http://github.com/banzaiman


                                                           http://www.flickr.com/photos/42033648@N00/372887164



Wednesday, October 26, 11
Ad

More Related Content

What's hot (20)

Torquebox - O melhor dos dois mundos
Torquebox - O melhor dos dois mundosTorquebox - O melhor dos dois mundos
Torquebox - O melhor dos dois mundos
Bruno Oliveira
 
Why Doesn't Java Has Instant Turnaround - Con-FESS 2012
Why Doesn't Java Has Instant Turnaround - Con-FESS 2012Why Doesn't Java Has Instant Turnaround - Con-FESS 2012
Why Doesn't Java Has Instant Turnaround - Con-FESS 2012
Anton Arhipov
 
Torquebox OSCON Java 2011
Torquebox OSCON Java 2011Torquebox OSCON Java 2011
Torquebox OSCON Java 2011
tobiascrawley
 
Mastering java bytecode with ASM - GeeCON 2012
Mastering java bytecode with ASM - GeeCON 2012Mastering java bytecode with ASM - GeeCON 2012
Mastering java bytecode with ASM - GeeCON 2012
Anton Arhipov
 
Torquebox @ Raleigh.rb - April 2011
Torquebox @ Raleigh.rb - April 2011Torquebox @ Raleigh.rb - April 2011
Torquebox @ Raleigh.rb - April 2011
tobiascrawley
 
DataMapper on Infinispan
DataMapper on InfinispanDataMapper on Infinispan
DataMapper on Infinispan
Lance Ball
 
The Enterprise Strikes Back
The Enterprise Strikes BackThe Enterprise Strikes Back
The Enterprise Strikes Back
Burke Libbey
 
Torquebox @ Charlotte.rb May 2011
Torquebox @ Charlotte.rb May 2011Torquebox @ Charlotte.rb May 2011
Torquebox @ Charlotte.rb May 2011
tobiascrawley
 
Java Bytecode For Discriminating Developers - GeeCON 2011
Java Bytecode For Discriminating Developers - GeeCON 2011Java Bytecode For Discriminating Developers - GeeCON 2011
Java Bytecode For Discriminating Developers - GeeCON 2011
Anton Arhipov
 
ZK_Arch_notes_20081121
ZK_Arch_notes_20081121ZK_Arch_notes_20081121
ZK_Arch_notes_20081121
WANGCHOU LU
 
Mashups with Drupal and QueryPath
Mashups with Drupal and QueryPathMashups with Drupal and QueryPath
Mashups with Drupal and QueryPath
Matt Butcher
 
Pi
PiPi
Pi
Hiro Asari
 
Oredev 2015 - Taming Java Agents
Oredev 2015 - Taming Java AgentsOredev 2015 - Taming Java Agents
Oredev 2015 - Taming Java Agents
Anton Arhipov
 
Soft-Shake 2016 : Jigsaw est prêt à tuer le classpath
Soft-Shake 2016 : Jigsaw  est prêt à tuer le classpathSoft-Shake 2016 : Jigsaw  est prêt à tuer le classpath
Soft-Shake 2016 : Jigsaw est prêt à tuer le classpath
Alexis Hassler
 
Java 7 Whats New(), Whats Next() from Oredev
Java 7 Whats New(), Whats Next() from OredevJava 7 Whats New(), Whats Next() from Oredev
Java 7 Whats New(), Whats Next() from Oredev
Mattias Karlsson
 
JVM
JVMJVM
JVM
Murali Pachiyappan
 
LyonJUG : Comment Jigsaw est prêt à tuer le classpath
LyonJUG : Comment Jigsaw est prêt à tuer le classpathLyonJUG : Comment Jigsaw est prêt à tuer le classpath
LyonJUG : Comment Jigsaw est prêt à tuer le classpath
Alexis Hassler
 
"Highlights from Java 10&11 and Future of Java" at Java User Group Bonn 2018 ...
"Highlights from Java 10&11 and Future of Java" at Java User Group Bonn 2018 ..."Highlights from Java 10&11 and Future of Java" at Java User Group Bonn 2018 ...
"Highlights from Java 10&11 and Future of Java" at Java User Group Bonn 2018 ...
Vadym Kazulkin
 
Ruby on Rails survival guide of an aged Java developer
Ruby on Rails survival guide of an aged Java developerRuby on Rails survival guide of an aged Java developer
Ruby on Rails survival guide of an aged Java developer
gicappa
 
LausanneJUG 2017 - Jigsaw est prêt à tuer le classpath
LausanneJUG 2017 - Jigsaw est prêt à tuer le classpathLausanneJUG 2017 - Jigsaw est prêt à tuer le classpath
LausanneJUG 2017 - Jigsaw est prêt à tuer le classpath
Alexis Hassler
 
Torquebox - O melhor dos dois mundos
Torquebox - O melhor dos dois mundosTorquebox - O melhor dos dois mundos
Torquebox - O melhor dos dois mundos
Bruno Oliveira
 
Why Doesn't Java Has Instant Turnaround - Con-FESS 2012
Why Doesn't Java Has Instant Turnaround - Con-FESS 2012Why Doesn't Java Has Instant Turnaround - Con-FESS 2012
Why Doesn't Java Has Instant Turnaround - Con-FESS 2012
Anton Arhipov
 
Torquebox OSCON Java 2011
Torquebox OSCON Java 2011Torquebox OSCON Java 2011
Torquebox OSCON Java 2011
tobiascrawley
 
Mastering java bytecode with ASM - GeeCON 2012
Mastering java bytecode with ASM - GeeCON 2012Mastering java bytecode with ASM - GeeCON 2012
Mastering java bytecode with ASM - GeeCON 2012
Anton Arhipov
 
Torquebox @ Raleigh.rb - April 2011
Torquebox @ Raleigh.rb - April 2011Torquebox @ Raleigh.rb - April 2011
Torquebox @ Raleigh.rb - April 2011
tobiascrawley
 
DataMapper on Infinispan
DataMapper on InfinispanDataMapper on Infinispan
DataMapper on Infinispan
Lance Ball
 
The Enterprise Strikes Back
The Enterprise Strikes BackThe Enterprise Strikes Back
The Enterprise Strikes Back
Burke Libbey
 
Torquebox @ Charlotte.rb May 2011
Torquebox @ Charlotte.rb May 2011Torquebox @ Charlotte.rb May 2011
Torquebox @ Charlotte.rb May 2011
tobiascrawley
 
Java Bytecode For Discriminating Developers - GeeCON 2011
Java Bytecode For Discriminating Developers - GeeCON 2011Java Bytecode For Discriminating Developers - GeeCON 2011
Java Bytecode For Discriminating Developers - GeeCON 2011
Anton Arhipov
 
ZK_Arch_notes_20081121
ZK_Arch_notes_20081121ZK_Arch_notes_20081121
ZK_Arch_notes_20081121
WANGCHOU LU
 
Mashups with Drupal and QueryPath
Mashups with Drupal and QueryPathMashups with Drupal and QueryPath
Mashups with Drupal and QueryPath
Matt Butcher
 
Oredev 2015 - Taming Java Agents
Oredev 2015 - Taming Java AgentsOredev 2015 - Taming Java Agents
Oredev 2015 - Taming Java Agents
Anton Arhipov
 
Soft-Shake 2016 : Jigsaw est prêt à tuer le classpath
Soft-Shake 2016 : Jigsaw  est prêt à tuer le classpathSoft-Shake 2016 : Jigsaw  est prêt à tuer le classpath
Soft-Shake 2016 : Jigsaw est prêt à tuer le classpath
Alexis Hassler
 
Java 7 Whats New(), Whats Next() from Oredev
Java 7 Whats New(), Whats Next() from OredevJava 7 Whats New(), Whats Next() from Oredev
Java 7 Whats New(), Whats Next() from Oredev
Mattias Karlsson
 
LyonJUG : Comment Jigsaw est prêt à tuer le classpath
LyonJUG : Comment Jigsaw est prêt à tuer le classpathLyonJUG : Comment Jigsaw est prêt à tuer le classpath
LyonJUG : Comment Jigsaw est prêt à tuer le classpath
Alexis Hassler
 
"Highlights from Java 10&11 and Future of Java" at Java User Group Bonn 2018 ...
"Highlights from Java 10&11 and Future of Java" at Java User Group Bonn 2018 ..."Highlights from Java 10&11 and Future of Java" at Java User Group Bonn 2018 ...
"Highlights from Java 10&11 and Future of Java" at Java User Group Bonn 2018 ...
Vadym Kazulkin
 
Ruby on Rails survival guide of an aged Java developer
Ruby on Rails survival guide of an aged Java developerRuby on Rails survival guide of an aged Java developer
Ruby on Rails survival guide of an aged Java developer
gicappa
 
LausanneJUG 2017 - Jigsaw est prêt à tuer le classpath
LausanneJUG 2017 - Jigsaw est prêt à tuer le classpathLausanneJUG 2017 - Jigsaw est prêt à tuer le classpath
LausanneJUG 2017 - Jigsaw est prêt à tuer le classpath
Alexis Hassler
 

Similar to JRuby and You (20)

The Enterprise Strikes Back
The Enterprise Strikes BackThe Enterprise Strikes Back
The Enterprise Strikes Back
Burke Libbey
 
Devon 2011-f-4-improve your-javascript
Devon 2011-f-4-improve your-javascriptDevon 2011-f-4-improve your-javascript
Devon 2011-f-4-improve your-javascript
Daum DNA
 
How we're building Wercker
How we're building WerckerHow we're building Wercker
How we're building Wercker
Micha Hernandez van Leuffen
 
De vuelta al pasado con SQL y stored procedures
De vuelta al pasado con SQL y stored proceduresDe vuelta al pasado con SQL y stored procedures
De vuelta al pasado con SQL y stored procedures
Norman Clarke
 
A Unified SOAP/JSON API with Symfony2
A Unified SOAP/JSON API with Symfony2A Unified SOAP/JSON API with Symfony2
A Unified SOAP/JSON API with Symfony2
Craig Marvelley
 
Rcos presentation
Rcos presentationRcos presentation
Rcos presentation
mskmoorthy
 
JRubyConf 2009
JRubyConf 2009JRubyConf 2009
JRubyConf 2009
John Woodell
 
Cross site calls with javascript - the right way with CORS
Cross site calls with javascript - the right way with CORSCross site calls with javascript - the right way with CORS
Cross site calls with javascript - the right way with CORS
Michael Neale
 
Introduction to ansible
Introduction to ansibleIntroduction to ansible
Introduction to ansible
Javier Arturo Rodríguez
 
Solr 4 highlights - Mark Miller
Solr 4 highlights - Mark MillerSolr 4 highlights - Mark Miller
Solr 4 highlights - Mark Miller
lucenerevolution
 
Macruby - RubyConf Presentation 2010
Macruby - RubyConf Presentation 2010Macruby - RubyConf Presentation 2010
Macruby - RubyConf Presentation 2010
Matt Aimonetti
 
RubyConf 2009
RubyConf 2009RubyConf 2009
RubyConf 2009
John Woodell
 
An introduction to Ember.js
An introduction to Ember.jsAn introduction to Ember.js
An introduction to Ember.js
codeofficer
 
Einführung in AngularJS
Einführung in AngularJSEinführung in AngularJS
Einführung in AngularJS
Sebastian Springer
 
Acceptance & Integration Testing With Behat (PBC11)
Acceptance & Integration Testing With Behat (PBC11)Acceptance & Integration Testing With Behat (PBC11)
Acceptance & Integration Testing With Behat (PBC11)
benwaine
 
Your first rails app - 2
 Your first rails app - 2 Your first rails app - 2
Your first rails app - 2
Blazing Cloud
 
Pocket Knife JS
Pocket Knife JSPocket Knife JS
Pocket Knife JS
Diogo Antunes
 
NoSQL CGN: CouchDB (11/2011)
NoSQL CGN: CouchDB (11/2011)NoSQL CGN: CouchDB (11/2011)
NoSQL CGN: CouchDB (11/2011)
Sebastian Cohnen
 
Практики применения JRuby
Практики применения JRubyПрактики применения JRuby
Практики применения JRuby
.toster
 
What You Need to Know About Lambdas - Jamie Allen (Typesafe)
What You Need to Know About Lambdas - Jamie Allen (Typesafe)What You Need to Know About Lambdas - Jamie Allen (Typesafe)
What You Need to Know About Lambdas - Jamie Allen (Typesafe)
jaxLondonConference
 
The Enterprise Strikes Back
The Enterprise Strikes BackThe Enterprise Strikes Back
The Enterprise Strikes Back
Burke Libbey
 
Devon 2011-f-4-improve your-javascript
Devon 2011-f-4-improve your-javascriptDevon 2011-f-4-improve your-javascript
Devon 2011-f-4-improve your-javascript
Daum DNA
 
De vuelta al pasado con SQL y stored procedures
De vuelta al pasado con SQL y stored proceduresDe vuelta al pasado con SQL y stored procedures
De vuelta al pasado con SQL y stored procedures
Norman Clarke
 
A Unified SOAP/JSON API with Symfony2
A Unified SOAP/JSON API with Symfony2A Unified SOAP/JSON API with Symfony2
A Unified SOAP/JSON API with Symfony2
Craig Marvelley
 
Rcos presentation
Rcos presentationRcos presentation
Rcos presentation
mskmoorthy
 
Cross site calls with javascript - the right way with CORS
Cross site calls with javascript - the right way with CORSCross site calls with javascript - the right way with CORS
Cross site calls with javascript - the right way with CORS
Michael Neale
 
Solr 4 highlights - Mark Miller
Solr 4 highlights - Mark MillerSolr 4 highlights - Mark Miller
Solr 4 highlights - Mark Miller
lucenerevolution
 
Macruby - RubyConf Presentation 2010
Macruby - RubyConf Presentation 2010Macruby - RubyConf Presentation 2010
Macruby - RubyConf Presentation 2010
Matt Aimonetti
 
An introduction to Ember.js
An introduction to Ember.jsAn introduction to Ember.js
An introduction to Ember.js
codeofficer
 
Acceptance & Integration Testing With Behat (PBC11)
Acceptance & Integration Testing With Behat (PBC11)Acceptance & Integration Testing With Behat (PBC11)
Acceptance & Integration Testing With Behat (PBC11)
benwaine
 
Your first rails app - 2
 Your first rails app - 2 Your first rails app - 2
Your first rails app - 2
Blazing Cloud
 
NoSQL CGN: CouchDB (11/2011)
NoSQL CGN: CouchDB (11/2011)NoSQL CGN: CouchDB (11/2011)
NoSQL CGN: CouchDB (11/2011)
Sebastian Cohnen
 
Практики применения JRuby
Практики применения JRubyПрактики применения JRuby
Практики применения JRuby
.toster
 
What You Need to Know About Lambdas - Jamie Allen (Typesafe)
What You Need to Know About Lambdas - Jamie Allen (Typesafe)What You Need to Know About Lambdas - Jamie Allen (Typesafe)
What You Need to Know About Lambdas - Jamie Allen (Typesafe)
jaxLondonConference
 
Ad

Recently uploaded (20)

Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
HCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser EnvironmentsHCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser Environments
panagenda
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded DevelopersLinux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Toradex
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
SOFTTECHHUB
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
HCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser EnvironmentsHCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser Environments
panagenda
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded DevelopersLinux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Toradex
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
SOFTTECHHUB
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
Ad

JRuby and You

  • 1. JRuby and You Hiro Asari Engine Yard Wednesday, October 26, 11
  • 2. History September 10, 2001 Source: Wikipedia Wednesday, October 26, 11
  • 4. Project Status • Current stable release: 1.6.5 (Oct 25, 2011) • Rails 3.1-compatible Wednesday, October 26, 11
  • 5. What’s next in 1.7? • JSR 292 (a.k.a. invokedynamic) support • Improved Ruby 1.9 support Wednesday, October 26, 11
  • 6. What’s in it for Java programmers? • REPL • Testing frameworks • Fun Wednesday, October 26, 11
  • 7. What’s in it for Rubyists? • Real threads • No more GIL • Mature garbage collector • Easy deployment Wednesday, October 26, 11
  • 8. Try JRuby http://jruby.org/tryjruby Wednesday, October 26, 11
  • 9. Getting JRuby wget http://bit.ly/jruby_bin_165 | tar xzvf - export PATH=$PATH:$PWD/jruby-1.6.5/bin Wednesday, October 26, 11
  • 10. jruby -S irb Wednesday, October 26, 11
  • 11. Java Integration require 'java' Wednesday, October 26, 11
  • 12. Loading JAR require 'example.jar' Wednesday, October 26, 11
  • 13. Importing Java Class StringBuffer = java.lang.StringBuffer sb = StringBuffer.new "foo" Wednesday, October 26, 11
  • 14. java_import java_import java.lang.StringBuffer java_import 'java.lang.StringBuffer' Wednesday, October 26, 11
  • 15. Static methods java.lang.System.currentTimeMillis java.lang.System.current_time_millis Wednesday, October 26, 11
  • 16. Static Fields java_import java.util.logging.Logger java_import java.util.loggin.Level Logger.global.log Level::SEVERE, "…" Wednesday, October 26, 11
  • 17. Constructor URL.new 'http://engineyard.com' URL.new 'http', 'engineyard.com', '/' Wednesday, October 26, 11
  • 18. Instance methods #given # void setPrice(int): car.setPrice(2000) car.price = 2000 # int getPrice() car.price Wednesday, October 26, 11
  • 19. Explicit Coercion measurement = 5 measurement.to_java Wednesday, October 26, 11
  • 20. Overloaded methods public class C { public static String method(String s) { return "String"; } public static String method(long l) { return "long"; } } Wednesday, October 26, 11
  • 21. Overloaded methods obj = C.new obj.method("foo") # => "String" obj.method(5) # => "long" Wednesday, October 26, 11
  • 22. Overloaded methods public class C { public String method(int i) { return "int"; } public String method(long l) { return "long"; } } Wednesday, October 26, 11
  • 23. Overloaded methods obj = C.new obj.method(5) # => "long" obj.method(5.to_java(Java::int)) obj.java_send :method, [Java::int], 5 Wednesday, October 26, 11
  • 24. Java Interfaces callable = java.util.concurrent.Executors.callable do puts "foo" end callable.call Wednesday, October 26, 11
  • 25. Complex Example with Akka Java source: http://bit.ly/lTClmr Ruby source: https://gist.github.com/1013227 http://www.engineyard.com/blog/2011/using- java-from-ruby-with-jruby-irb/ Wednesday, October 26, 11
  • 26. GUI Redcar http://redcareditor.com/ Wednesday, October 26, 11
  • 27. Grafting Rails into Spring MVC Wednesday, October 26, 11
  • 28. Pet Clinic • Example database- backed web app for Spring framework Wednesday, October 26, 11
  • 29. Requests JRuby / /vets /rack/ Java/ Spring App Wednesday, October 26, 11
  • 30. Adding Route diff --git a/src/main/webapp/WEB-INF/jsp/vets.jsp b/src/main/webapp/WEB-INF/jsp/vets.jsp index cff2154..0d99817 100644 --- a/src/main/webapp/WEB-INF/jsp/vets.jsp +++ b/src/main/webapp/WEB-INF/jsp/vets.jsp @@ -23,7 +23,7 @@ <table class="table-buttons"> <tr> <td> - <a href="<spring:url value="/vets.xml" htmlEscape="true" />">View as XML</a> + <a href="<spring:url value="/rack/vets.xml" htmlEscape="true" />">View as XML</a> </td> </tr> </table> Wednesday, October 26, 11
  • 31. Cucumber • http://cukes.info • Testing framework for describing software behavior in plain English Wednesday, October 26, 11
  • 32. Cucumber Feature: Pets Scenario: Edit Pet Given I am on the owners search page And I press "Find Owners" And I follow "George Franklin" And I follow "Edit Pet" When I fill in "Name" with "Leoni" And press "Update Pet" Then I should see "Leoni" Wednesday, October 26, 11
  • 33. Cucumber test Stand by while Tomcat finishes booting... Using the default profile... ............................................................F-............. (::) failed steps (::) expected: /xml/, got: "text/html;charset=utf-8" (using =~) Diff: @@ -1,2 +1,2 @@ -/xml/ +text/html;charset=utf-8 (RSpec::Expectations::ExpectationNotMetError) org/jruby/RubyProc.java:268:in `call' ./features/step_definitions/xml_json_steps.rb:12:in `(root)':in `/^I should see an XML document$/' features/vets.feature:6:in `Then I should see an XML document' Failing Scenarios: cucumber features/vets.feature:3 # Scenario: View vets as XML 13 scenarios (1 failed, 12 passed) 75 steps (1 failed, 1 skipped, 73 passed) 0m7.709s rake aborted! Cucumber failed Wednesday, October 26, 11
  • 34. diff --git a/pom.xml b/pom.xml index 9e22f83..0810701 100644 --- a/pom.xml +++ b/pom.xml @@ -211,6 +211,18 @@ <scope>provided</scope> </dependency> + <!-- JRuby and JRuby-Rack --> + <dependency> + <groupId>org.jruby</groupId> + <artifactId>jruby-complete</artifactId> + <version>1.6.0</version> + </dependency> + <dependency> + <groupId>org.jruby.rack</groupId> + <artifactId>jruby-rack</artifactId> + <version>1.0.8</version> + </dependency> + <!-- Test dependencies --> <dependency> <groupId>org.junit</groupId> Wednesday, October 26, 11
  • 35. diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml index 8d02684..60ed6cb 100644 --- a/src/main/webapp/WEB-INF/web.xml +++ b/src/main/webapp/WEB-INF/web.xml @@ -87,6 +87,21 @@ <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> + + <listener> + <listener-class>org.jruby.rack.RackServletContextListener</listener-class> + </listener> + + <servlet> + <servlet-name>rack</servlet-name> + <servlet-class>org.jruby.rack.RackServlet</servlet-class> + </servlet> + + <servlet-mapping> + <servlet-name>rack</servlet-name> + <url-pattern>/rack/*</url-pattern> + </servlet-mapping> + <!-- Defines the 'default' servlet (usually for service static resources). Wednesday, October 26, 11
  • 36. diff --git a/src/main/webapp/WEB-INF/lib/app.rb b/src/main/webapp/WEB-INF/lib/ app.rb index 6ab5b3c..4398fb4 100644 --- a/src/main/webapp/WEB-INF/lib/app.rb +++ b/src/main/webapp/WEB-INF/lib/app.rb @@ -1,6 +1,33 @@ require 'builder' require 'erb' +require 'spring_helpers' + +helpers do + include Spring +end get '/rack/' do '<h1>Sinatra</h1>' end + +get '/rack/vets.xml' do + content_type 'application/vnd.petclinic+xml' + builder do |xml| + xml.instruct! + xml.vets do + clinic.vets.each do |vet| + xml.vetList do + xml.id vet.id + xml.firstName vet.firstName + xml.lastName vet.lastName + vet.specialties.each do |spec| + xml.specialties do + xml.id spec.id + xml.name spec.name + end + end + end + end + end + end +end Wednesday, October 26, 11
  • 37. Requests / /vets JRuby /owners Java/ / /vets /owners /1/pets Spring App Wednesday, October 26, 11
  • 38. diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml index 60ed6cb..f64b34d 100644 --- a/src/main/webapp/WEB-INF/web.xml +++ b/src/main/webapp/WEB-INF/web.xml @@ -92,16 +92,6 @@ <listener-class>org.jruby.rack.RackServletContextListener</listener-class> </listener> - <servlet> - <servlet-name>rack</servlet-name> - <servlet-class>org.jruby.rack.RackServlet</servlet-class> - </servlet> - - <servlet-mapping> - <servlet-name>rack</servlet-name> - <url-pattern>/rack/*</url-pattern> - </servlet-mapping> - <!-- Defines the 'default' servlet (usually for service static resources). @@ -162,6 +152,16 @@ <url-pattern>/</url-pattern> </servlet-mapping> + <filter> + <filter-name>RackFilter</filter-name> + <filter-class>org.jruby.rack.RubyFirstRackFilter</filter-class> + </filter> + + <filter-mapping> + <filter-name>RackFilter</filter-name> + <url-pattern>/*</url-pattern> + </filter-mapping> + <filter> <filter-name>httpMethodFilter</filter-name> <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class> Wednesday, October 26, 11
  • 39. The Book http://pragprog.com/book/ jruby/using-jruby 25% off for one week only: http://bit.ly/vd4Mhj Wednesday, October 26, 11
  • 40. Engine Yard 500 free hours http://engineyard.com Wednesday, October 26, 11
  • 41. Questions? Twitter @hiro_asari G+ http://gplus.to/hiroasari LinkedIn http://linkedin.com/in/hiroasari [email protected] [email protected] http://github.com/banzaiman http://www.flickr.com/photos/42033648@N00/372887164 Wednesday, October 26, 11