<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>f3yourmind &#187; JRuby</title>
	<atom:link href="http://aslamkhan.net/tag/jruby/feed/" rel="self" type="application/rss+xml" />
	<link>http://aslamkhan.net</link>
	<description>"There are no limits. There are only plateaus, and you must not stay there, you must go beyond them." - Bruce Lee</description>
	<lastBuildDate>Wed, 01 Sep 2010 22:25:14 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Introduction to BDD</title>
		<link>http://aslamkhan.net/events/introduction-to-bdd/</link>
		<comments>http://aslamkhan.net/events/introduction-to-bdd/#comments</comments>
		<pubDate>Wed, 30 Jul 2008 11:21:44 +0000</pubDate>
		<dc:creator>Aslam</dc:creator>
				<category><![CDATA[Architecture and Development]]></category>
		<category><![CDATA[Conferences, Speaking Gigs, etc.]]></category>
		<category><![CDATA[Agile]]></category>
		<category><![CDATA[BDD]]></category>
		<category><![CDATA[JCSE]]></category>
		<category><![CDATA[JRuby]]></category>
		<category><![CDATA[TDD]]></category>

		<guid isPermaLink="false">http://aslamkhan.net/?p=43</guid>
		<description><![CDATA[
I will be giving a short introduction to behavior driven development (BDD) at the XP forum on 13 August 2008.  As usual, I&#8217;m using the opportunity to subtly throw in some other practices such as coding for readability and designing good messages.  I will also touch on mocking in tests as well.
I&#8217;ve been having immense fun putting together [...]]]></description>
			<content:encoded><![CDATA[<div>
<p>I will be giving a short introduction to <a href="http://behaviour-driven.org/">behavior driven development</a> (BDD) at the XP forum on 13 August 2008.  As usual, I&#8217;m using the opportunity to subtly throw in some other practices such as coding for readability and designing good messages.  I will also touch on mocking in tests as well.</p>
<p>I&#8217;ve been having immense fun putting together some code examples for this talk and I hope to demo BDD using <a href="http://junit.sourceforge.net/">JUnit</a>, <a href="http://jbehave.org/">JBehave</a>, <a href="http://rspec.info/">RSpec</a> (using the rbehave story runner on <a href="http://jruby.codehaus.org/">JRuby</a> to test Java) and <a href="http://jtestr.codehaus.org/">JTestR</a> (which looks like a really exciting little project).</p>
<p>Come along and enjoy the fun.  Details and registration is on the <a href="http://www.jcse.org.za/events.php?itemid=27">JCSE web site</a>.</p>
<p><strong>Update 1: The </strong><a href="http://aslamkhan.net/wp-content/uploads/2008/08/bdd-fun-src.zip"><strong>Source Code for BDD Presentation</strong></a><strong> is now available.</strong></p>
<p><strong>Update 2: The presentation is now available for download </strong><a href="http://aslamkhan.net/wp-content/uploads/2008/08/IntroToBDD.mov"><strong>here</strong></a><strong>.  It&#8217;s a 5MB Quicktime movie file. It&#8217;s not a continuous play movie, so you need to click through to the next slide.</strong></div>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Faslamkhan.net%2Fevents%2Fintroduction-to-bdd%2F&amp;linkname=Introduction%20to%20BDD"><img src="http://aslamkhan.net/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://aslamkhan.net/events/introduction-to-bdd/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
<enclosure url="http://aslamkhan.net/wp-content/uploads/2008/08/IntroToBDD.mov" length="5177011" type="video/quicktime" />
		</item>
		<item>
		<title>JRuby with Andrea Provaglio</title>
		<link>http://aslamkhan.net/events/jruby-with-andrea-provaglio/</link>
		<comments>http://aslamkhan.net/events/jruby-with-andrea-provaglio/#comments</comments>
		<pubDate>Tue, 18 Dec 2007 17:21:10 +0000</pubDate>
		<dc:creator>Aslam</dc:creator>
				<category><![CDATA[Conferences, Speaking Gigs, etc.]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JCSE]]></category>
		<category><![CDATA[JRuby]]></category>
		<category><![CDATA[PBT]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://aslamkhan.net/uncategorized/jruby-with-andrea-provaglio/</guid>
		<description><![CDATA[PBT Group and the Johannesburg Centre for Software Engineering are hosting a JRuby master class led by Andrea Provaglio.  I met Andrea at the Software Architecture Workshop in Arosa, Switzerland this year and I cannot speak more highly of him.  Just check out his web site for details.  It&#8217;s not often that we get a chance to have such learned [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.pbt.co.za">PBT Group</a> and the <a href="http://www.jcse.org.za">Johannesburg Centre for Software Engineering</a> are hosting a JRuby master class led by <a href="http://andreaprovaglio.com/">Andrea Provaglio</a>.  I met Andrea at the Software Architecture Workshop in Arosa, Switzerland this year and I cannot speak more highly of him.  Just check out his web site for details.  It&#8217;s not often that we get a chance to have such learned architects and practitioners in South Africa.  Let&#8217;s take advantage of this opportunity.  The greater the support, the easier it is for us to pull in heavy hitters in this industry for future events.There is a class scheduled for Johannesburg on 16 January 2008 and Cape Town on 29 January 2008.  Registration is online at the JCSE <a href="http://www.jcse.org.za">website</a>.  Just follow the links from the front page.See you there!</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Faslamkhan.net%2Fevents%2Fjruby-with-andrea-provaglio%2F&amp;linkname=JRuby%20with%20Andrea%20Provaglio"><img src="http://aslamkhan.net/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://aslamkhan.net/events/jruby-with-andrea-provaglio/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Get Cooking with JRuby on Rails</title>
		<link>http://aslamkhan.net/software-development/get-cooking-with-jruby-on-rails/</link>
		<comments>http://aslamkhan.net/software-development/get-cooking-with-jruby-on-rails/#comments</comments>
		<pubDate>Tue, 18 Dec 2007 16:35:54 +0000</pubDate>
		<dc:creator>Aslam</dc:creator>
				<category><![CDATA[Architecture and Development]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JRuby]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://aslamkhan.net/java/get-cooking-with-jruby-on-rails/</guid>
		<description><![CDATA[Some of the companies that I interact claim that they will never switch to Ruby on Rails (or just plain &#8216;ol Ruby) for that matter.  But with JRuby reaching 1.0 status (and currently on 1.0.2 with 1.1b1 already released) this changes the situation somewhat.  Now it is possible to develop Rails apps and [...]]]></description>
			<content:encoded><![CDATA[<p>Some of the companies that I interact claim that they will never switch to Ruby on Rails (or just plain &#8216;ol Ruby) for that matter.  But with JRuby reaching 1.0 status (and currently on 1.0.2 with 1.1b1 already released) this changes the situation somewhat.  Now it is possible to develop Rails apps and run it on your Java infrastructure that make use of native JDBC connections and a whole bunch more.<br />
<h3>Pre-requisites</h3>
<p>Since we want to run a Ruby on Rails app on a Java application server, we need to have a Java web container such as Tomcat, Jetty or Glassfish.  In my case, I&#8217;ll be dropping the app into into a Glassfish domain.  I guess that this should work just fine for Tomcat as well, but I have not verified this as yet.You also need a database and I will be using MySQL.  If you are going to use another database, you need to make sure that the ActiveRecord-JDBC adapter has been developed for the DB.  ActiveRecord is the ORM for Rails apps.  Currently, there are ActiveRecord-JDBC adaptors for HypersonicSQL, Derby, MySQL and PostgreSQL.  This is true for version 0.6 of ActiveRecord-JDBC.  For other adapters, you will need to specify a proper JDBC URL in your application&#8217;s database configuration file, <code>config/database.yml</code>.  This will make a lot more sense once you finish this exercise.All of the above (except or ActiveRecord, of course) should be stock standard goodies on any self-respecting Java development box.  With this place, let&#8217;s get cooking.<br />
<h3>Install JRuby</h3>
<p>Download the JRuby bin distribution from the JRuby downloads page. At the time of writing this, 1.1b1 has been released.  I am currently using the 1.02 release.  Unzip/untar the file to somewhere convenient, add an environment variable <code>JRUBY_HOME</code> to point to the extracted directory, and add <code>JRUBY_HOME/bin</code> to your path.
<pre>	/&gt; cd ~/tools	/&gt; tar xzvf jruby-bin-1.02.tar.gz</pre>
<pre><span style="white-space: pre" class="Apple-tab-span">	</span>/&gt; export JRUBY_HOME=~/tools/jruby-1.0.2</pre>
<pre><span style="white-space: pre" class="Apple-tab-span">	</span>/&gt; export PATH=$PATH:$JRUBY_HOME/bin</pre>
<p>You can verify your JRuby installation with:
<pre>	/&gt; jruby -v</pre>
<pre><span style="white-space: pre" class="Apple-tab-span">	</span>ruby 1.8.5 (2007-11-01 rev 4810) [i386-jruby1.0.2]</pre>
<p> You will notice two versions being reported.  The first tells us that the ruby implementation is version 1.8.5 and the second tells us that it is running on jruby 1.0.2 on i386 platform.  If you are new to ruby, then you need to know that there are different implementations of ruby, with the definitive one called MRI (Matz&#8217;s Ruby Implementation &#8211; Matz is the original author of ruby).  JRuby is an attempt at a complete port of MRI to Java, aiming to eliminate all dependencies on C libraries.  This is one of the significant points about JRuby: it is pure Java.<br />
<h3>Install RubyGems</h3>
<p>The closest Java equivalent of RubyGems  is Maven or Ant+Ivy.  Gems is a library and dependency management tool for ruby.  On a native ruby install, you would have to download and install RubyGems, but JRuby already has RubyGems rolled in.  Take a peek at JRUBY_HOME/bin and you should see an executable file called gem.  So, nothing more to do here.  What the heck, let&#8217;s verify that RubyGem is working.
<pre>	/&gt; jruby -S gem -v</pre>
<pre>	0.9.4</pre>
<p>If <code>$JRUBY_HOME/bin</code> is first in your path, then you can try <code>/&gt; gem -v</code>.  The <code>-S</code> tells jruby to run the command that follows from <code>$JRUBY_HOME</code>.For the ruby folk, you should realize that JRuby has rolled in RubyGems version 0.9.4 which is as fresh as it comes.The closest Java equivalent of RubyGems that I can think of is perhaps Maven or ANT+Ivy.  But RubyGems takes the prize hands-down for its absolute simplicity.  Install rake and Rails below and see what I mean.<br />
<h3>Install Rake</h3>
<p> Rake is a really good build tool for ruby (i.e a make for ruby, hence the goofy name).  Once you start writing rake build scripts, you will wonder why one earth you thought ANT is nice.  Anyway, let&#8217;s install rake.
<pre>	/&gt; jruby -S gem install rake</pre>
<h3>Install Rails</h3>
<p>Now that you&#8217;ve seen the goodness of RubyGems, install Rails and the ActiveRecord for JDBC.
<pre>	/&gt; jruby -S gem install rails -v 1.2.6 -y --no-rdoc --no-ri</pre>
<pre>	/&gt; jruby -S gem install activerecord-jdbcmysql-adapter --include-dependencies</pre>
<p>We are deliberately installing Rails version 1.2.6.  Rails 2.0.1 was released in early December 2007 and I have not taken 2.0.1 for a drive under jruby yet.  So, we&#8217;ll stick to version 1.2.6 which is still great.<br />
<h3>Get MySQL Ready</h3>
<p> We&#8217;re heading for the home straight with all this setup and configuration nonsense.  Just a couple of things to do.
<ul>
<li>Copy the MySQL JDBC driver to <code>$JRUBY_HOME/lib</code>.</li>
<li>Create a MySQL database called <code>testapp_development</code>.  Rails apps require three databases; one for development (suffixed <code>_development</code>), one for unit testing (suffixed _test and is wiped clean with every test run) and one for production (suffixed _production).  For this exercise, we will just use the development database with full rights given to the MySQL user <code>root</code> with no pasword.</li>
</ul>
<h3>Create the Rails App</h3>
<p>Now the fun starts! Finally!The next command will create a directory with the same name as your application.  So, change to a directory that will contain your rails applications.  In my case, I keep my applications in <code>~/projects/jruby</code>.
<pre>	/&gt; cd ~/projects/jruby</pre>
<pre>	/&gt; jruby -S rails testapp</pre>
<p>Now you should have a directory called <code>testapp</code>.  Let&#8217;s see if our app works. Yes, in rails-land, the app can already be fired up!
<pre>	/&gt; cd ~/projects/jruby/testapp</pre>
<pre>	/&gt; jruby script/server</pre>
<p>This fires up <code>webrick</code>, a built in http server with ruby support built in. Just point your browser to <code>http://0.0.0.0:3000</code> and you should see the Rails happy page.  Kill <code>webrick</code> by hitting <code>CTRL+C</code>.<br />
<h3>Link up to your database</h3>
<p>Edit the file <code>config/database.yml</code> and change it as follows. Note that the line <code>socket: /tmp/mysql.sock</code> must be removed.
<pre>	development:</pre>
<pre>  	  adapter: mysql</pre>
<pre>  	  database: testapp_development</pre>
<pre>  	  username: root</pre>
<pre>  	  password:</pre>
<p>and
<pre>	production:</pre>
<pre>  	  adapter: mysql</pre>
<pre>  	  database: testapp_development</pre>
<pre>  	  username: root</pre>
<pre>  	  password:</pre>
<p> YML files are files that store configuration using <a href="http://www.yaml.org">YAML</a>, which is a <em>&#8221; is a straightforward machine parsable data serialization format designed for human readability&#8221;</em>.Now, let us inform the Rails app that we are using <code>ActiveRecord-JDBC</code>.  Add the following to the file <code>config/environment.rb</code> just before the line <code>Rails::Initializer.run do |config|</code>.
<pre>  if RUBY_PLATFORM =~ /java/</pre>
<pre>    require 'rubygems'</pre>
<pre>    RAILS_CONNECTION_ADAPTERS = %w(jdbc)</pre>
<pre>  end</pre>
<h3>Create a table (the Rails way)</h3>
<p> Sure, we can write a simple SQL script to create the table we want, but for fun, let&#8217;s do it using some Rails sugar.  You can keep your app running in webrick and still do the this.  Just open up another command or shell, switch to your project directory and get going.  This is one of the nicest bits of Rails &#8211; you can do most things without a restart of your application server.
<pre>	/&gt; jruby script/generate migration AddGadgetsTable</pre>
<p>This should have created a file <code>db/migrate/001_add_gadgets_table.rb</code>.  Open this file and edit it as follows.
<pre>	class AddGadgetsTable &lt; ActiveRecord::Migration</pre>
<pre>	   def self.up</pre>
<pre>	      create_table :gadgets do |table|</pre>
<pre>	         table.column :name,  :string, :null =&gt; false</pre>
<pre>	         table.column :color, :string, :null =&gt; false</pre>
<pre>	      end</pre>
<pre>	   end</pre>
<pre>	   def self.down</pre>
<pre>	      drop_table :gadgets</pre>
<pre>	   end</pre>
<pre>	end</pre>
<p>After saving the file, run the following command to create the table.  Actually, we&#8217;re <em>migrating</em> our existing database to <em>version 001</em>!  Database refactoring is a definite goal of Rails.  It may not be perfect, but it is certainly better than maintaining a bunch of SQL files.
<pre>	/&gt; jruby -S rake db:migrate</pre>
<p> Even if you&#8217;ve never seen ruby before, the above is certainly readable and you can easily understand that we intend to create a table called <code>gadgets</code> with two columns <code>name</code> and <code>color</code>.  Actually, there are more than these two columns.  Have a look at the table structure and check that a primary key colum <code>id</code> has been added as well.<br />
<h3>Generate Scaffolding to maintain the table</h3>
<p>I know, I know, I know!  Code generation for anything but the most trivial of code can be dramatic for newbies but real code takes a lot more effort.  The point here is just to get some Rails code up and running so that we can deploy it in a Java application server.  So, please bear with me.
<pre>	/&gt; jruby script/generate scaffold gadget</pre>
<p>Fire up <code>webrick</code> and visit the URL <code>http://0.0.0.0:3000/gadgets</code>.  You should see a page with an empty list of gadgets and CRUD links.<br />
<h3>Get ready to WAR</h3>
<p>We need a few additional rake tasks to be able to build a WAR for our Rails application.  The Goldspike plugin for Rails does just that.  Let&#8217;s install the Goldspike plugin.
<pre>	/&gt; jruby script/plugin install \</pre>
<pre>		svn://rubyforge.org/var/svn/jruby-extras/trunk/rails-integration/plugins/goldspike</pre>
<p>All that&#8217;s required is to add the WAR dependency on the MySQL driver.  What&#8217;s great about Goldspike is that we can declare Maven dependencies.  Great combination: RubyGems for Ruby-land and Maven for JRuby-land!  Open the file <code>vendor/plugins/goldspike/lib/war_config.rb</code> and add the following line to the list of <code># default java libraries</code> block.
<pre>	add_java_library(maven_library ('mysql', 'mysql-connector-java', '5.0.5'))</pre>
<h3>Build the WAR</h3>
<p><span style="font-size: 19px; font-weight: bold" class="Apple-style-span"></span><span style="font-size: 19px; font-weight: bold" class="Apple-style-span"></span>Now build the WAR using rake.
<pre>	/&gt; jruby -S rake war:standalone:create</pre>
<p>If you look in the root of your application directory, there should be a file testapp.war<br />
<h3>Drop it into Glassfish</h3>
<p> Start your Glassfish domain, log in to the Glassfish admin console and click the <em>Deploy Web Application</em> link.  Browse to the <code>testapp</code> directory and select the <code>testapp.war</code> file.  If the app is not enabled, then select <code>testapp</code>, and click <em>Enable</em>.<br />
<h3>See it in action</h3>
<p>Point your browser to <code>http://localhost:8080/testapp</code>.  You should see the Rails happy page, and <code>http://localhost:8080/testapp/gadgets</code> has the CRUD for our <code>Gadget</code> object.<span style="font-style: italic" class="Apple-style-span">As easy as pie! And just as nice!</span></p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Faslamkhan.net%2Fsoftware-development%2Fget-cooking-with-jruby-on-rails%2F&amp;linkname=Get%20Cooking%20with%20JRuby%20on%20Rails"><img src="http://aslamkhan.net/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://aslamkhan.net/software-development/get-cooking-with-jruby-on-rails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
