SlideShare a Scribd company logo
1JRuby in Java ProjectsDenis Lutz
2Motivation: Problem, SolutionJRuby as languageJava and Ruby Integration Ruby CommunityShow Case DemoUsage areas for JRubyAgenda
3Motivation
4Lets redefine our thinkingWhat is our task?What is the shortest path to the solution?Since…Not the solving of complicated tasks is the goal…but solving our task in the easiest possible wayMotivation
5Java has a huge set of toolsJVM scripting languages are present (Groovy)You can find a tool for everythingThe java magazines are writing about scripting languagesTheory
6Projectwide scripting support not the rule, more an exceptionAnt = scripting language =>  XML is our scripting languageIf scripting language integration => Ant / Spring is the environmentAdhoc scripting areas are randomly used by single devsInstead a major scripting support strategy is missingYoung developers face only java or ant Young devs are on their own to find more expressive languagesReal world praxis
7Entering JRuby
8scripting tool as one of main and known toolsscripting language as the surrounding environment and entry point (not Ant)clearly decleared scripting language standarddefinition of taks areas for the scripting languageeasy and powerfull communication with the underlying operating systempowerfull language features instead of XML tools (Ant, Maven)knowledge reuse because of definition of several scripting areas in a projektfrom GUIs and IDEs to automation and console proceduresfrom enterprisy java community to a fun community in rubyGoal
9What is JRubyJRuby = implementation of Ruby in Java
Runs in JVM and integrates perfectly into Java environments
very expressive
mature
huge community powered by the Ruby on Rails framework10Front End (MVC)Build managementTesting, specifically integration testingImport/Export APIsCode generationWe can use JRuby in many project areas
11Facets of JRuby
12Download Jruby at www.jruby.orgExtractAdd to  $PATHTest your installation with “jruby –v” on the consoleCommand execution with“jruby –S ‘command’ ”jruby –S irb        -> Will start the JRuby consoleGet started with JRuby in 3 mins…
13Simple SyntaxEverything is an objectBlocksSelf contained ( contains most useful libs out of the box)Open classesPrinciple of least surpriseMost imressive language features
14Simple object creation
15Create your class and use it, lightweight and easy!
16Everything is an object
17Blocks, the most amazing and powerful feature ever
18Lets call JRuby from Javapublic void callJRuby() {  ScriptEngineManager m = new ScriptEngineManager();  ScriptEngine rubyEngine = m.getEngineByName("jruby");  if (rubyEngine==null)       throw new RuntimeException("Did not find my ruby engine");  ScriptContext context = rubyEngine.getContext();  context.setAttribute("world","Programmierer",ScriptContext.ENGINE_SCOPE);  try{    File f = new File("hello1.rb");     BufferedReader br = new BufferedReader(new FileReader(f));     rubyEngine.eval(br, context); // (1)   } catch (ScriptException e) {   e.printStackTrace();   } catch (FileNotFoundException fnfe) {     System.err.println(fnfe.getMessage());   }}
19require 'java’java_import java.lang.System => Java::JavaLang::System version = System.getProperties["java.runtime.version"] => "1.6.0_17-b04-248-10M3025” import java.util.ArrayListlist = ArrayList.new => #<Java::JavaUtil::ArrayList:0x2bf09a31> ruby-1.8.7-p334 :042 > iterator = list.iterator => #<#<Class:01x41a7c484>:0x367c218e> ruby-1.8.7-p334 :043 > iterator.java_class => class java.util.AbstractList$Itr ruby-1.8.7-p334 :044 > list.get(1)NativeException: java.lang.IndexOutOfBoundsException: Index: 1, Size: 0Lets call Java from Jruby und use your legacy systems
20Ruby’s Community
21Very strong community, why?Got powered by Ruby on Rails (MVC Framework)Fun oriented communityMotivated hobby programmers, who can be 9-5 employees ;-)Get into positive cycle of beeing threated well and wanting more rubyGEMS = ruby libraries, created by the communityCommunity
22Endless amounts of gems
23Find most popular gems in one place, rated by the community
24Live Demo: Using a GEM
25we want to communicate with a REST APIshould be usable within a buildor inside a java class of courseShould provide an easy API for our java classThe taskEasiest solution (a base for it) ?
26Choose your gemHTTPartyChoose HTTParty as the gem for REST communication
27Install the GEM
28Write our nice little class
29Use it immidiatelly on the console to play with it
30We knew from one site about the best fitting GEM for our taskWe had no troubles installing itI can try my written code on the consoleit just works, doesn’t matter what you installits my experience after two years using ruby, yours will be the sameWhy was this great?
31Integration with Java
32Yes its right, Rails got over JSF (java standard) in the meanwhileIs this still a new and not known technology for you?Rails (Ruby) popularity
33Yes, possible and widely usedJRuby on Rails Frontend as war file in TomcatRails Front Ends in Java Projects possible everything else is waste of money and developers frustrationNo risk, tell to your java influenced boss: „its just a war file“  No server infrastructure changes neededDeploy a Ruby on Rails Application in a java warjruby -S gem install -y rails warbler$RAILS_APP_ROOT/jruby -S warble war
34Java Build with Rake
35Rake as build tool in Java projectsBasic problem:ANT is accepted, Maven the „new standard“None of them is sufficient for the task we want to doWhy?
36Projectsetup, its in the Wiki, well because Ant cant do it ;-) Folders and File management„if“ – „else“ , can you declare it out of your head now in Ant?  Declare a method in your build? Oh, yea no problem let me just look into Ant APILoading of fixtures, possible with some XML setup againServer startup? I am doing it by hand and each new developer has to learn the specifics Maven „the biggest hype“ that helps me even less then AntProblems with Ant and others…
37Full language power in your build, not XMLWe can still call our old Ant tasksUNIX operations as if we would be on the consoleMethod declarations, as simple as possibleReuse of a language we already usenot learning new XML frameworksWhat we want
38Rake does all you want :project setupmethodsoperating system callsobjects in your buildfile operationsIvy integrationRake is the solution, rubys build tool
39Rake in 3 mins, nothing is easier!
40Call classic and custom Ant tasks from rake if needed
41Operating system communicationFile managementFolder managementTalk to your operating system as from the console
42Some rake possibilities = just full ruby power
43In/Out API for your project
44Its difficult to process files as well as different formats in javaImport or Export is mostly a focused single taskCan be done separated, by one developerNo requirement to do it in javaCustomer data import is a very common and important taskUse JRuby to provide an import / export APIData processing much fasterEasy CSV, Excel, XML processing Generate projects specific formats for importJRuby as your In/Out API of any project
45JRuby as your In/Out API of any project
46(Integration) Testing
47Integration tests are the best candidate to do it with JRubyAbstract, mimal input, very high coverageAre easy to keep out of the java environment systemCan be perfectly done with pure rubyWEBRAT GEM as JRuby LibraryIntegration Testing
48Webrat Example
49GUI Testing APIEvaluates the pure HTML outputNo browser setup or dependency to run your testsWrite your tests fast in ruby Cover the complete application workflow with minimal effortCan be run automatically in backgroud while developingExcellent to give fast feedback about application stabilityWebrat
50Expected Result from Jruby integration
51All mentioned task areas can be done easier in JRubyMore choices of tools, as would it be only with JavaKnowledge reuse in different project areasWork is getting more lightweigtFrom java IDEs to fast editorsPerfect interaction between different parts of the buildExpected result

More Related Content

PDF
Using Java from Ruby with JRuby IRB
PDF
Connecting the Worlds of Java and Ruby with JRuby
PDF
JRuby and You
PPTX
Mastering Java Bytecode - JAX.de 2012
PPTX
Java 7 Whats New(), Whats Next() from Oredev
PPTX
Why Doesn't Java Has Instant Turnaround - Con-FESS 2012
KEY
JavaOne 2011 - JVM Bytecode for Dummies
PPT
Java, Ruby & Rails
Using Java from Ruby with JRuby IRB
Connecting the Worlds of Java and Ruby with JRuby
JRuby and You
Mastering Java Bytecode - JAX.de 2012
Java 7 Whats New(), Whats Next() from Oredev
Why Doesn't Java Has Instant Turnaround - Con-FESS 2012
JavaOne 2011 - JVM Bytecode for Dummies
Java, Ruby & Rails

What's hot (19)

PPTX
Mastering java bytecode with ASM - GeeCON 2012
PDF
TorqueBox - Ultrapassando a fronteira entre Java e Ruby
KEY
Mashups with Drupal and QueryPath
ODP
Open Source Compiler Construction for the JVM
PPTX
Java Bytecode For Discriminating Developers - GeeCON 2011
KEY
Jruby synergy-of-ruby-and-java
PPTX
Java byte code & virtual machine
PDF
Introduction to the Java bytecode - So@t - 20130924
PDF
Beyond JVM - YOW! Sydney 2013
PDF
JavaScript Library Overview
PDF
Spring into rails
PPT
55 New Features in Java 7
PDF
The Enterprise Strikes Back
KEY
Ruby on Rails survival guide of an aged Java developer
PDF
Seeking Clojure
PPTX
Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov
PDF
Introduction to Ruby on Rails
PPTX
Java bytecode and classes
Mastering java bytecode with ASM - GeeCON 2012
TorqueBox - Ultrapassando a fronteira entre Java e Ruby
Mashups with Drupal and QueryPath
Open Source Compiler Construction for the JVM
Java Bytecode For Discriminating Developers - GeeCON 2011
Jruby synergy-of-ruby-and-java
Java byte code & virtual machine
Introduction to the Java bytecode - So@t - 20130924
Beyond JVM - YOW! Sydney 2013
JavaScript Library Overview
Spring into rails
55 New Features in Java 7
The Enterprise Strikes Back
Ruby on Rails survival guide of an aged Java developer
Seeking Clojure
Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov
Introduction to Ruby on Rails
Java bytecode and classes
Ad

Similar to JRuby in Java Projects (20)

PDF
Bitter Java, Sweeten with JRuby
PDF
JRuby - Enterprise 2.0
KEY
TSSJS 2011 - JRuby
PDF
Why JRuby?
PDF
JRoR Deploying Rails on JRuby
PDF
JRuby in the enterprise
PDF
JRuby - Java version of Ruby
PDF
JRuby - The Best of Java and Ruby
PDF
JRuby Basics
PPT
Practical JRuby
PPT
Dynamic Languages on the JVM
PDF
Ola Bini J Ruby Power On The Jvm
PPT
Introduction to JRuby And JRuby on Rails
PDF
JRuby and Google App Engine
PPT
Ruby On Google App Engine 2nd Athens Ruby Me
PDF
From java-to-ruby-book-summary
PPTX
Adventures of java developer in ruby world
PDF
A jar-nORM-ous Task
PDF
Real World Technologies
PPTX
JRuby deployments
Bitter Java, Sweeten with JRuby
JRuby - Enterprise 2.0
TSSJS 2011 - JRuby
Why JRuby?
JRoR Deploying Rails on JRuby
JRuby in the enterprise
JRuby - Java version of Ruby
JRuby - The Best of Java and Ruby
JRuby Basics
Practical JRuby
Dynamic Languages on the JVM
Ola Bini J Ruby Power On The Jvm
Introduction to JRuby And JRuby on Rails
JRuby and Google App Engine
Ruby On Google App Engine 2nd Athens Ruby Me
From java-to-ruby-book-summary
Adventures of java developer in ruby world
A jar-nORM-ous Task
Real World Technologies
JRuby deployments
Ad

Recently uploaded (20)

PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Approach and Philosophy of On baking technology
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Empathic Computing: Creating Shared Understanding
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
KodekX | Application Modernization Development
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPT
Teaching material agriculture food technology
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
sap open course for s4hana steps from ECC to s4
Advanced methodologies resolving dimensionality complications for autism neur...
MIND Revenue Release Quarter 2 2025 Press Release
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Dropbox Q2 2025 Financial Results & Investor Presentation
Approach and Philosophy of On baking technology
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Understanding_Digital_Forensics_Presentation.pptx
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Empathic Computing: Creating Shared Understanding
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
KodekX | Application Modernization Development
Per capita expenditure prediction using model stacking based on satellite ima...
Reach Out and Touch Someone: Haptics and Empathic Computing
Teaching material agriculture food technology
Mobile App Security Testing_ A Comprehensive Guide.pdf

JRuby in Java Projects

  • 1. 1JRuby in Java ProjectsDenis Lutz
  • 2. 2Motivation: Problem, SolutionJRuby as languageJava and Ruby Integration Ruby CommunityShow Case DemoUsage areas for JRubyAgenda
  • 4. 4Lets redefine our thinkingWhat is our task?What is the shortest path to the solution?Since…Not the solving of complicated tasks is the goal…but solving our task in the easiest possible wayMotivation
  • 5. 5Java has a huge set of toolsJVM scripting languages are present (Groovy)You can find a tool for everythingThe java magazines are writing about scripting languagesTheory
  • 6. 6Projectwide scripting support not the rule, more an exceptionAnt = scripting language => XML is our scripting languageIf scripting language integration => Ant / Spring is the environmentAdhoc scripting areas are randomly used by single devsInstead a major scripting support strategy is missingYoung developers face only java or ant Young devs are on their own to find more expressive languagesReal world praxis
  • 8. 8scripting tool as one of main and known toolsscripting language as the surrounding environment and entry point (not Ant)clearly decleared scripting language standarddefinition of taks areas for the scripting languageeasy and powerfull communication with the underlying operating systempowerfull language features instead of XML tools (Ant, Maven)knowledge reuse because of definition of several scripting areas in a projektfrom GUIs and IDEs to automation and console proceduresfrom enterprisy java community to a fun community in rubyGoal
  • 9. 9What is JRubyJRuby = implementation of Ruby in Java
  • 10. Runs in JVM and integrates perfectly into Java environments
  • 13. huge community powered by the Ruby on Rails framework10Front End (MVC)Build managementTesting, specifically integration testingImport/Export APIsCode generationWe can use JRuby in many project areas
  • 15. 12Download Jruby at www.jruby.orgExtractAdd to $PATHTest your installation with “jruby –v” on the consoleCommand execution with“jruby –S ‘command’ ”jruby –S irb -> Will start the JRuby consoleGet started with JRuby in 3 mins…
  • 16. 13Simple SyntaxEverything is an objectBlocksSelf contained ( contains most useful libs out of the box)Open classesPrinciple of least surpriseMost imressive language features
  • 18. 15Create your class and use it, lightweight and easy!
  • 20. 17Blocks, the most amazing and powerful feature ever
  • 21. 18Lets call JRuby from Javapublic void callJRuby() { ScriptEngineManager m = new ScriptEngineManager(); ScriptEngine rubyEngine = m.getEngineByName("jruby"); if (rubyEngine==null) throw new RuntimeException("Did not find my ruby engine"); ScriptContext context = rubyEngine.getContext(); context.setAttribute("world","Programmierer",ScriptContext.ENGINE_SCOPE); try{ File f = new File("hello1.rb"); BufferedReader br = new BufferedReader(new FileReader(f)); rubyEngine.eval(br, context); // (1) } catch (ScriptException e) { e.printStackTrace(); } catch (FileNotFoundException fnfe) { System.err.println(fnfe.getMessage()); }}
  • 22. 19require 'java’java_import java.lang.System => Java::JavaLang::System version = System.getProperties["java.runtime.version"] => "1.6.0_17-b04-248-10M3025” import java.util.ArrayListlist = ArrayList.new => #<Java::JavaUtil::ArrayList:0x2bf09a31> ruby-1.8.7-p334 :042 > iterator = list.iterator => #<#<Class:01x41a7c484>:0x367c218e> ruby-1.8.7-p334 :043 > iterator.java_class => class java.util.AbstractList$Itr ruby-1.8.7-p334 :044 > list.get(1)NativeException: java.lang.IndexOutOfBoundsException: Index: 1, Size: 0Lets call Java from Jruby und use your legacy systems
  • 24. 21Very strong community, why?Got powered by Ruby on Rails (MVC Framework)Fun oriented communityMotivated hobby programmers, who can be 9-5 employees ;-)Get into positive cycle of beeing threated well and wanting more rubyGEMS = ruby libraries, created by the communityCommunity
  • 26. 23Find most popular gems in one place, rated by the community
  • 28. 25we want to communicate with a REST APIshould be usable within a buildor inside a java class of courseShould provide an easy API for our java classThe taskEasiest solution (a base for it) ?
  • 29. 26Choose your gemHTTPartyChoose HTTParty as the gem for REST communication
  • 31. 28Write our nice little class
  • 32. 29Use it immidiatelly on the console to play with it
  • 33. 30We knew from one site about the best fitting GEM for our taskWe had no troubles installing itI can try my written code on the consoleit just works, doesn’t matter what you installits my experience after two years using ruby, yours will be the sameWhy was this great?
  • 35. 32Yes its right, Rails got over JSF (java standard) in the meanwhileIs this still a new and not known technology for you?Rails (Ruby) popularity
  • 36. 33Yes, possible and widely usedJRuby on Rails Frontend as war file in TomcatRails Front Ends in Java Projects possible everything else is waste of money and developers frustrationNo risk, tell to your java influenced boss: „its just a war file“ No server infrastructure changes neededDeploy a Ruby on Rails Application in a java warjruby -S gem install -y rails warbler$RAILS_APP_ROOT/jruby -S warble war
  • 38. 35Rake as build tool in Java projectsBasic problem:ANT is accepted, Maven the „new standard“None of them is sufficient for the task we want to doWhy?
  • 39. 36Projectsetup, its in the Wiki, well because Ant cant do it ;-) Folders and File management„if“ – „else“ , can you declare it out of your head now in Ant? Declare a method in your build? Oh, yea no problem let me just look into Ant APILoading of fixtures, possible with some XML setup againServer startup? I am doing it by hand and each new developer has to learn the specifics Maven „the biggest hype“ that helps me even less then AntProblems with Ant and others…
  • 40. 37Full language power in your build, not XMLWe can still call our old Ant tasksUNIX operations as if we would be on the consoleMethod declarations, as simple as possibleReuse of a language we already usenot learning new XML frameworksWhat we want
  • 41. 38Rake does all you want :project setupmethodsoperating system callsobjects in your buildfile operationsIvy integrationRake is the solution, rubys build tool
  • 42. 39Rake in 3 mins, nothing is easier!
  • 43. 40Call classic and custom Ant tasks from rake if needed
  • 44. 41Operating system communicationFile managementFolder managementTalk to your operating system as from the console
  • 45. 42Some rake possibilities = just full ruby power
  • 46. 43In/Out API for your project
  • 47. 44Its difficult to process files as well as different formats in javaImport or Export is mostly a focused single taskCan be done separated, by one developerNo requirement to do it in javaCustomer data import is a very common and important taskUse JRuby to provide an import / export APIData processing much fasterEasy CSV, Excel, XML processing Generate projects specific formats for importJRuby as your In/Out API of any project
  • 48. 45JRuby as your In/Out API of any project
  • 50. 47Integration tests are the best candidate to do it with JRubyAbstract, mimal input, very high coverageAre easy to keep out of the java environment systemCan be perfectly done with pure rubyWEBRAT GEM as JRuby LibraryIntegration Testing
  • 52. 49GUI Testing APIEvaluates the pure HTML outputNo browser setup or dependency to run your testsWrite your tests fast in ruby Cover the complete application workflow with minimal effortCan be run automatically in backgroud while developingExcellent to give fast feedback about application stabilityWebrat
  • 53. 50Expected Result from Jruby integration
  • 54. 51All mentioned task areas can be done easier in JRubyMore choices of tools, as would it be only with JavaKnowledge reuse in different project areasWork is getting more lightweigtFrom java IDEs to fast editorsPerfect interaction between different parts of the buildExpected result
  • 55. 52My personal, subjective impressionYou will reach more, having to know lessAchieve more with less work using ruby
  • 56. 53http://www.jruby.org/http://kenai.com/projects/jruby/pages/HomeJruby console with “jruby –S irb”http://www.cygwin.com/ (Unix Console replacement for Windows)EditorsTextmate (MacOs)http://www.e-texteditor.com/ (Windows)IDE’shttp://www.jetbrains.com/ruby/http://www.aptana.com/products/radrails (Eclipse Plugin)http://wiki.netbeans.org/Ruby (Netbeans Ruby Support)Further informations
  • 57. 54Thanks a lot and have fun with JRuby!