<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Tom Purl's Web Site &#187; jruby</title>
	<atom:link href="http://tompurl.com/tag/jruby/feed/" rel="self" type="application/rss+xml" />
	<link>http://tompurl.com</link>
	<description>My '83 Datsun On The Side Of The Information Superhighway</description>
	<lastBuildDate>Sat, 12 Jun 2010 01:15:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='tompurl.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/620cc5862148afd2b2d0242871afa4ab?s=96&#038;d=http://s2.wp.com/i/buttonw-com.png</url>
		<title>Tom Purl's Web Site &#187; jruby</title>
		<link>http://tompurl.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://tompurl.com/osd.xml" title="Tom Purl&#039;s Web Site" />
	<atom:link rel='hub' href='http://tompurl.com/?pushpress=hub'/>
		<item>
		<title>Running Depot On Tomcat</title>
		<link>http://tompurl.com/2010/03/25/running-depot-on-tomcat/</link>
		<comments>http://tompurl.com/2010/03/25/running-depot-on-tomcat/#comments</comments>
		<pubDate>Thu, 25 Mar 2010 01:49:49 +0000</pubDate>
		<dc:creator>Tom Purl</dc:creator>
				<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jruby]]></category>
		<category><![CDATA[agile-web-development-with-rails]]></category>
		<category><![CDATA[ruby-on-rails]]></category>
		<category><![CDATA[tomcat]]></category>

		<guid isPermaLink="false">http://tompurl.com/?p=200</guid>
		<description><![CDATA[This is my second article about running the Depot application from the Agile Development With Rails book on top of Jruby. The first article, which covers development and testing, can be found here. This article covers the following topics: Packaging our RoR project into a WAR file Deploying that WAR file on Tomcat Please note [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tompurl.com&blog=3216699&post=200&subd=tompurl&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>This is my second article about running the Depot application from the <a href="http://pragprog.com/titles/rails3/agile-web-development-with-rails-third-edition">Agile Development With Rails</a> book on top of Jruby.  The <a href="http://tompurl.com/2010/03/02/running-the-depot-application-with-jruby/">first article</a>, which covers development and testing, can be found <a href="http://tompurl.com/2010/03/02/running-the-depot-application-with-jruby/">here</a>.</p>
<p>This article covers the following topics:</p>
<ul>
<li>Packaging our RoR project into a WAR file</li>
<li>Deploying that WAR file on Tomcat</li>
</ul>
<p>Please note that this article only covers deploying Jruby-On-Rails applications in a non-Production (i.e. non-public-facing) environment.  This example is designed to allow a <strong>developer</strong> to deploy a Jruby-On-Rails application <strong>on her workstation</strong>.  If you want to install Tomcat in a public-facing environment, then you need a different tutorial <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<h2>Tomcat Installation</h2>
<p><a title="Home page for the Apache Tomcat app server" href="http://tomcat.apache.org/">Tomcat</a> was my choice for the following reasons:</p>
<ol>
<li>It’s very easy to install.  Just unpack it and go (if you already have the proper version of Java installed).</li>
<li>It’s very easy to administer on my netbook (which is where I’m learning about RoR and Jruby).</li>
<li>It’s relatively lightweight compared to JBoss or WebLogic.</li>
<li>It’s very easy to deploy war files.  Just drop them in <code>$TOMCAT_HOME/webapps</code>, restart Tomcat, and you’re up-and-running.</li>
</ol>
<p>So let’s install Tomcat:</p>
<pre class="brush: plain;">
$ cd /tmp
$ wget http://apache.opensourceresources.org/tomcat/tomcat-6/v6.0.24/bin/apache-tomcat-6.0.24.tar.gz
$ tar xvfz apache-tomcat-6.0.24.tar.gz
$ sudo cp -r apache-tomcat-6.0.24 /opt
# please replace tom:tom with your user and group
$ sudo chown -R tom:tom /opt/apache-tomcat-6.0.24
</pre>
<p>Assuming that you have the minimum version of Java (I’m using 1.6.0_15 from the sun-java6-jdk Ubuntu package), you can start Tomcat like this:</p>
<pre class="brush: plain;">
$ cd /opt/apache-tomcat-6.0.24/bin
$ ./startup.sh
Using CATALINA_BASE:   /opt/apache-tomcat-6.0.24
Using CATALINA_HOME:   /opt/apache-tomcat-6.0.24
Using CATALINA_TMPDIR: /opt/apache-tomcat-6.0.24/temp
Using JRE_HOME:        /usr/lib/jvm/java-6-sun
Using CLASSPATH:       /opt/apache-tomcat-6.0.24/bin/bootstrap.jar
</pre>
<p>Great, now you can test your installation by pointing your browser at the following url:</p>
<ul>
<li>http://localhost:8080</li>
</ul>
<p>You can also shut the server down using the <code>shutdown.sh</code> script from the same directory.</p>
<h2>Packaging Depot In A WAR File</h2>
<p>Now that Tomcat is up-and-running, let’s build our WAR file.  If you haven’t already installed <code>warbler</code>, then you can do so with the following command:</p>
<pre class="brush: plain;">
$ jruby -S gem install warbler
</pre>
<p><a href="http://blog.nicksieger.com/articles/2007/09/04/warbler-a-little-birdie-to-introduce-your-rails-app-to-java">Warbler</a> is a gem that makes it very easy to package RoR applications as WAR files. However, before we can use it, we need to tell it that we’re using the <code>activerecord-jdbcsqlite3-adapter</code> driver.  Here’s how you do that:</p>
<ol>
<li>Run the <code>warble config</code> command from the root directory of your project. This command will create the <code>config/warble.rb</code> file.</li>
<li>Add the following line to the newly-created <code>config/warble.rb</code> file:
<ol>
<li><code>config.gems &lt;&lt; "activerecord-jdbcsqlite3-adapter"</code></li>
</ol>
</li>
</ol>
<p>That’s it!  Now you can build your war file:</p>
<pre class="brush: plain;">
$ warble
</pre>
<p>In a minute or so, you should see a file named <code>depot-jruby.war</code> in the root of your project directory.  If you need to rebuild you war file, then simply execute the following command:</p>
<pre class="brush: plain;">
$ warble war:clean &amp;amp;&amp;amp; warble
</pre>
<h2>Deploying On Tomcat</h2>
<p>Now we can finally deploy the WAR file to our Tomcat instance.  Here’s how I do it on my machine:</p>
<pre class="brush: plain;">
$ cd /opt/apache-tomcat-6.0.24
$ cp /home/tom/Dev/ruby/depot-jruby/depot-jruby.war ./webapps
$ ./bin/shutdown.sh &amp;amp;&amp;amp; ./bin/startup.sh
</pre>
<p>Then you can test your application by visiting the following URL:</p>
<ul>
<li>http://localhost:8080/depot-jruby/store</li>
</ul>
<h2>Conclusion</h2>
<p>I know that I said this in my previous tutorial, but that was a lot easier than I thought it would be.  It only took 3 simple steps, and the Tomcat installation step only needs to be done once.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/tompurl.wordpress.com/200/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/tompurl.wordpress.com/200/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/tompurl.wordpress.com/200/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/tompurl.wordpress.com/200/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/tompurl.wordpress.com/200/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/tompurl.wordpress.com/200/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/tompurl.wordpress.com/200/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/tompurl.wordpress.com/200/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/tompurl.wordpress.com/200/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/tompurl.wordpress.com/200/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tompurl.com&blog=3216699&post=200&subd=tompurl&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://tompurl.com/2010/03/25/running-depot-on-tomcat/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7b972ff5d62434623ade7ad88b02aa99?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">tpurl</media:title>
		</media:content>
	</item>
		<item>
		<title>Running The Depot Application With Jruby</title>
		<link>http://tompurl.com/2010/03/02/running-the-depot-application-with-jruby/</link>
		<comments>http://tompurl.com/2010/03/02/running-the-depot-application-with-jruby/#comments</comments>
		<pubDate>Tue, 02 Mar 2010 02:49:04 +0000</pubDate>
		<dc:creator>Tom Purl</dc:creator>
				<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[jruby]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[agile-development-with-rails]]></category>

		<guid isPermaLink="false">http://tompurl.com/?p=179</guid>
		<description><![CDATA[I completed the Depot application from the Agile Development With Rails book, and I feel that I have a good understanding of the basics of developing with Ruby on Rails. It’s a great framework, and creating the Depot application was a fun and enlightening process. I thought that it might be equally enlightening to “port” [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tompurl.com&blog=3216699&post=179&subd=tompurl&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>I completed the Depot application from the <a title="PragProg page for the book" href="http://pragprog.com/titles/rails3/agile-web-development-with-rails-third-edition">Agile Development With Rails</a> book, and I feel that I have a good understanding of the basics of developing with Ruby on Rails.  It’s a great framework, and creating the <strong>Depot</strong> application was a fun and enlightening process.</p>
<p>I thought that it might be equally enlightening to “port” the Depot application to <a title="Jruby home page" href="http://jruby.org/">Jruby</a> using the <a title="The Jruby on Rails page on the Jruby wiki" href="http://kenai.com/projects/jruby/pages/JRubyOnRails">Jruby On Rails</a> libraries.  I had two basic milestones in mind:</p>
<ol>
<li><strong>Development &amp; Testing</strong> – I wanted to be able to develop and test my application just like I did with CRuby, using tools such as <code>mongrel</code> and <code>rake</code>.</li>
<li><strong>J2EE Deployment</strong> – The most popular process for deploying a Java-based application is to build a WAR file and then deploy it to a Java application server such as Tomcat (which was my choice).  I wanted to be able to complete these steps with my RoR application.</li>
</ol>
<p>The entire process was surprisingly easy.  The first milestone, <strong>Development and Testing</strong>, is covered in this article.  The <strong>J2EE Deployment</strong> milestone will be covered in a <a title="Running Depot On Tomcat article" href="http://tompurl.com/2010/03/25/running-depot-on-tomcat/">different blog article</a>.</p>
<h2>Development &amp; Testing</h2>
<p>Here are some simple steps that will have your application running with <code>mongrel</code> very quickly.</p>
<p><strong>Please note</strong> that I am executing the steps below on a netbook running Ubuntu 9.10.  These commands should work on most Linux distributions, however.  Also, they should work with a few small adjustments on a Windows machine.</p>
<h3>Prepping Your Project Directory</h3>
<p>First, you’re not going to want to make these changes to your original version of the Depot code.  You will probably want to create a copy of it that is designed to work with Jruby.  Here’s how I did it on my machine:</p>
<pre><code>$ cd /home/tom/Dev/ruby
$ cp -r depot depot-jruby
</code></pre>
<p>The location of your <code>depot</code> folder will probably be different on your machine, but I’m sure that you can make the necessary adjustments <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Also, please  note that it is a good idea to “freeze” your rails version now if you have not done so already.  You can do this by executing the following command:</p>
<pre><code>$ cd /home/tom/Dev/ruby/depot-jruby
$ jruby -S rake rails:freeze:edge RELEASE=2.2.2
</code></pre>
<h3>Installing Jruby</h3>
<p>Next, you’ll want to install Jruby.  There’s a lot of ways of doing this, but this method worked pretty well on my development machine:</p>
<pre><code>$ cd /tmp
$ wget http://jruby.kenai.com/downloads/1.4.0/jruby-bin-1.4.0.tar.gz
$ tar xvfz jruby-bin-1.4.0.tar.gz
$ sudo cp -r jruby-1.4.0 /opt
# please replace tom:tom with your user and group
$ sudo chown -R tom:tom /opt/jruby-1.4.0
$ sudo ln -s /opt/jruby-1.4.0 /opt/jruby
</code></pre>
<p>Then simply add <code>/opt/jruby</code> to your <code>PATH</code>, and see if you can execute <code>jirb</code>.</p>
<h3>Installing Rails And Other Libraries</h3>
<p>This process is just as easy using Jruby as it is using CRuby.</p>
<p>Install the gems using these commands:</p>
<pre><code>$ jruby -S gem install rails --version 2.2.2
$ jruby -S gem install mongrel jruby-openssl jdbc-sqlite3
</code></pre>
<p>A few notes on those commands:</p>
<ul>
<li>Prepend the gem command with <code>jruby -S</code> to ensure that you are using the right version of the <code>gem</code> command.  This also works with any other Jruby command, such as <code>rake</code>.</li>
<li>Since the example uses the 2.2.2 version of Rails, we’re going to need it too.</li>
<li><code>jdbc-sqlite3</code> is the Java version of the sqlite3 DB driver.</li>
<li>The <code>jruby-openssl</code> package is nice to have regardless of what you’re installing with <code>rubygems</code>.</li>
</ul>
<h3>Making Depot Safe For JDBC</h3>
<p>You can’t use the C-based database drivers with Jruby, but luckily, the Jruby developers have made it very easy to use the JDBC-based equivalents.</p>
<p>First, make sure that you are using version <strong>0.9.2</strong> of the <code>activerecord-jdbc-adapter</code> driver or higher.  You can check this by executing the following command:</p>
<pre><code>$ jruby -S gem list | grep activerecord-jdbc-adapter
activerecord-jdbc-adapter (0.9.2)
</code></pre>
<p>Next, execute the following command from the root directory of your project:</p>
<pre><code>$ jruby script/generate jdbc
exists  config/initializers
create  config/initializers/jdbc.rb
create  lib/tasks
create  lib/tasks/jdbc.rake
</code></pre>
<p>That’s it!  Your Depot application is now ready to use Jruby-on-Rails.</p>
<p><strong>Please note</strong> that I <strong>did not modify my config/database.yml file</strong> or hack any part of the Rails libraries to make JDBC work.  These steps <strong>used</strong> to be necessary, but the command listed above gives you a much easier and cleaner way of using JDBC.  For more information, please check out this article:</p>
<ul>
<li><a href="http://blog.nicksieger.com/articles/2009/10/12/fresh-0-9-2-activerecord-jdbc-adapter-release">Fresh 0.9.2 activerecord-jdbc-adapter Release</a></li>
</ul>
<h3>Test</h3>
<p>To test my work, I did the following:</p>
<ul>
<li>I ran the <code>mongrel</code> app server and executed some manual tests of the Depot web site.  That worked well.</li>
<li>I execute all of my tests using the <code>rake test</code> command.  This also worked as well as it had with the CRuby version of my application.</li>
</ul>
<p>Success!  Now it would be nice to review all of the files that changed or were added.  Since I checked my project into my <code>git</code> repository before making any changes, I can get the information that I need pretty easily:</p>
<pre><code>$ git status
# branch master
# Changes to be committed:
#   (use "git reset HEAD &lt;file&gt;..." to unstage)
#
#       new file:   config/initializers/jdbc.rb
#       new file:   lib/tasks/jdbc.rake
</code></pre>
<p>That’s it!  No code or config changes were necessary.</p>
<h2>Conclusion</h2>
<p>As you can see, it’s fairly easy to “port” the Depot application to use Java-based versions of <code>mongrel</code>, <code>rails</code>, and the other libraries from the <a title="PragProg page for the book" href="http://pragprog.com/titles/rails3/agile-web-development-with-rails-third-edition">Agile Development With Rails</a> book.  In my <a title="Running Depot On Tomcat article" href="http://tompurl.com/2010/03/25/running-depot-on-tomcat/">next article</a>, I will take this application and deploy it on top of a Tomcat server.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/tompurl.wordpress.com/179/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/tompurl.wordpress.com/179/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/tompurl.wordpress.com/179/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/tompurl.wordpress.com/179/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/tompurl.wordpress.com/179/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/tompurl.wordpress.com/179/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/tompurl.wordpress.com/179/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/tompurl.wordpress.com/179/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/tompurl.wordpress.com/179/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/tompurl.wordpress.com/179/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tompurl.com&blog=3216699&post=179&subd=tompurl&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://tompurl.com/2010/03/02/running-the-depot-application-with-jruby/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7b972ff5d62434623ade7ad88b02aa99?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">tpurl</media:title>
		</media:content>
	</item>
		<item>
		<title>Testing The Waters Of Jruby &amp; JDBC</title>
		<link>http://tompurl.com/2009/08/21/testing-the-waters-of-jruby-jdbc/</link>
		<comments>http://tompurl.com/2009/08/21/testing-the-waters-of-jruby-jdbc/#comments</comments>
		<pubDate>Fri, 21 Aug 2009 13:09:17 +0000</pubDate>
		<dc:creator>Tom Purl</dc:creator>
				<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[apache-derby]]></category>
		<category><![CDATA[jdbc]]></category>
		<category><![CDATA[jruby]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://tompurl.wordpress.com/?p=43</guid>
		<description><![CDATA[I was recently tasked with writing a command-line script in Jruby that performed simple CRUD operations against a simple database table. I&#8217;ve written tons of scripts in the past that manipulated tables, but I had never done so using Jruby. I therefore decided to first write a &#8220;bare-minimum&#8221; test script that would help me dip [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tompurl.com&blog=3216699&post=43&subd=tompurl&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>I was recently tasked with writing a command-line script in Jruby that performed simple CRUD operations against a simple database table.  I&#8217;ve written tons of scripts in the past that manipulated tables, but I had never done so using Jruby.  I therefore decided to first write a &#8220;bare-minimum&#8221; test script that would help me dip my toes in this unfamiliar water.</p>
<p>I wanted to write my test script against a database manager that ran on my laptop, but I didn&#8217;t want to go through the hassle of installing and configuring Oracle or MySql.  Also, I soon learned that a lot of Ruby database drivers don&#8217;t work with Jruby, so I needed a small, simple database that had a good JDBC driver.  I ended up installing and configuring <a title="Apache Derby" href="http://db.apache.org/derby">Apache Derby</a>, and it worked out very well for me.</p>
<p>So anyways, here&#8217;s the script (jdbctest.rb):</p>
<pre class="brush: ruby;">
require 'java'
require './derbyclient.jar'
require './derbytools.jar'

# This example assumes that you have the free DerbyDB software installed on
# your machine.  It also assumes that you are running it in &quot;server&quot; mode by
# executing the startNetworkServer.bat script.

# This is what I'm using instead of Class.forName(&quot;org.apache.derby.jdbc.ClientDriver&quot;).newInstance()
import 'org.apache.derby.jdbc.ClientDriver'

connString = &quot;jdbc:derby://localhost:1527/MyDbTest&quot;
conn = Java::JavaSql::DriverManager.getConnection(connString)

stmt = conn.createStatement

rs = stmt.executeQuery(&quot;select * from derbyDb&quot;)

while (rs.next) do
    puts &quot;#{rs.getString(&quot;NUM&quot;)} -- #{rs.getString(&quot;ADDR&quot;)}&quot;
end

rs.close
stmt.close
conn.close()
</pre>
<p>I then placed the <strong>jdbctest.rb</strong> script in a folder with the <strong>derbyclient.jar</strong> and <strong>derbytools.jar</strong> file, and then executed the script like this:</p>
<pre>
<pre>c:\Dev\jruby\somefolder&gt;jruby .\jdbctest.rb
180 -- Grand Ave.
1910 -- Union St.
</pre>
</pre>
<p>To make this script work, you need to do the following:</p>
<ol>
<li>Install Derby using this tutorial:  <a title="Step 1 - Install Software" href="http://db.apache.org/derby/papers/DerbyTut/install_software.html">Step 1 &#8211; Install Software</a>
<ul>
<li>This is a very simple task that took me all of 6 minutes after downloading the software.</li>
</ul>
</li>
<li>Create the <strong>MyDbTest</strong> database and the <strong>derbyDB</strong> table using this tutorial: <a title="Step 2 - ij Basics" href="http://db.apache.org/derby/papers/DerbyTut/ij_intro.html">Step 2 &#8211; ij Basics</a>
<ul>
<li>You should also populate this table using the SQL located under the <strong>Execute SQL Statements</strong> section.</li>
</ul>
</li>
<li>Once you&#8217;ve created and queried your table using <code>ij</code>, start your Derby server using this tutorial:  <a title="Step 4 - Derby Network Server" href="http://db.apache.org/derby/papers/DerbyTut/ns_intro.html">Step 4 &#8211; Derby Network Server</a>
<ul>
<li>You should validate the server using <code>ij</code>.  Please see the <strong>Test network server connection with ij</strong> section in the <strong>Step 4</strong> tutorial for help.</li>
</ul>
</li>
</ol>
<p>Please note that this might seem like a lot of work, but it&#8217;s really very simple, especially when you compare it installing and configuring most relational database managers.  It took me about 20 minutes from A to Z, and I had no prior experience with Derby.</p>
<p>That&#8217;s it!  I hope that this tutorial helps a few other people who want to get started with Jruby and JDBC.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/tompurl.wordpress.com/43/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/tompurl.wordpress.com/43/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/tompurl.wordpress.com/43/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/tompurl.wordpress.com/43/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/tompurl.wordpress.com/43/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/tompurl.wordpress.com/43/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/tompurl.wordpress.com/43/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/tompurl.wordpress.com/43/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/tompurl.wordpress.com/43/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/tompurl.wordpress.com/43/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tompurl.com&blog=3216699&post=43&subd=tompurl&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://tompurl.com/2009/08/21/testing-the-waters-of-jruby-jdbc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7b972ff5d62434623ade7ad88b02aa99?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">tpurl</media:title>
		</media:content>
	</item>
		<item>
		<title>Jruby vs. Groovy For Administrative Scripting</title>
		<link>http://tompurl.com/2008/11/13/jruby-vs-groovy-for-administrative-scripting/</link>
		<comments>http://tompurl.com/2008/11/13/jruby-vs-groovy-for-administrative-scripting/#comments</comments>
		<pubDate>Thu, 13 Nov 2008 17:29:52 +0000</pubDate>
		<dc:creator>Tom Purl</dc:creator>
				<category><![CDATA[Review]]></category>
		<category><![CDATA[administration]]></category>
		<category><![CDATA[groovy]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jruby]]></category>
		<category><![CDATA[scripting]]></category>

		<guid isPermaLink="false">http://tompurl.wordpress.com/?p=9</guid>
		<description><![CDATA[Update (8/8/09): When I was originally comparing Jruby &#38; Groovy, I was under the impression that Jruby was a beta-quality product, and its cryptic error messages seemed to prove this point.  After a bit more research, I learned that Jruby is a robust and high-quality Ruby implementation and that all dynamic languages can give you [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tompurl.com&blog=3216699&post=9&subd=tompurl&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p><strong>Update (8/8/09): </strong>When I was originally comparing Jruby &amp; Groovy, I was under the impression that Jruby was a beta-quality product, and its cryptic error messages seemed to prove this point.  After a bit more research, I learned that Jruby is a robust and high-quality Ruby implementation and that <strong>all</strong> dynamic languages can give you cryptic errors on occasion.  Many thanks to the knowledgeable Jruby and Groovy developers who set me straight.</p>
<h3>Background</h3>
<p>I&#8217;m a middleware systems administrator for a living, and I often find that I need to write a script that has to interact with proprietary Java libraries. In the past, this meant writing a small Java program that would use the proprietary libraries, and then wrapping that program in a small shell script. This process was OK, but it did have its warts. For example, Java is a fairly verbose language. Going through all of the syntactic hoops just to write a simple program can be tedious.</p>
<p>A little over a year ago, I then discovered Groovy and Jruby. Both languages were very elegant, and I could see how they could both boost my scripting productivity dramatically. I therefore compared both languages for my scripting tasks, and, in the end, I determined that Groovy was just a better language. Here&#8217;s part of my rationale:</p>
<ul class="circle">
<li><strong>A More Stable Interpreter</strong> &#8211; Jruby would often give extremely cryptic errors when you made a mistake, while Groovy did a much better job of pointing out any problems.</li>
<li><strong>A Compiler</strong> &#8211; At the time, Groovy had a compiler (groovyc) that use could use to compile your scripts into bytecode. This tool made it much easier for me to deploy Groovy code in my environment. Jruby has since introduced a similar tool, but it didn&#8217;t exist during my initial evaluation.</li>
</ul>
<p>Now I&#8217;m on a new project, and we need to write a bunch of administrative scripts in a hurry. We have the same requirements as my old project, but just before I could dive into my Groovy interpreter, I found out that a lot of the Java developers on my team were ga-ga for Ruby. I therefore decided that it would be nice to evaluate both languages again, one year later. If Jruby is nearly as stable as Groovy for my needs, then it might be a good idea to start writing my scripts with it.</p>
<h3>Evaluation</h3>
<p>Before I could start my evaluation, I thought it might be a good idea to re-acquaint myself with Ruby. I read &#8220;Everyday Scripting With Ruby&#8221; a little over six months ago and thought that it was an excellent tutorial on both Ruby <em>and</em> agile scripting. I therefore decided to try running some of the examples in that book with Jruby to bring myself back up-to-speed.</p>
<p>In &#8220;Everyday Scripting With Ruby&#8221;, the first chapter encourages you to enter invalid code into <strong>irb</strong>, which is the Ruby interactive interpreter. This exercise shows you how to read the error messages returned by irb. Here&#8217;s the line of code:</p>
<pre> 100 -= 43</pre>
<p>And here&#8217;s what the latest-and-greatest (1.1.5) version of <strong>jirb</strong> (Jruby&#8217;s version of irb) returns when you enter that:</p>
<pre> irb(main):001:0&gt; 100 -= 43
 SyntaxError: (irb):2: , unexpected tOP_ASGN

         from E:/apps/jruby-1.1.5/lib/ruby/1.8/irb/workspace.rb:81:in `irb_binding'
         from E:/apps/jruby-1.1.5/lib/ruby/1.8/irb/workspace.rb:53:in `eval'
         from E:/apps/jruby-1.1.5/lib/ruby/1.8/irb/workspace.rb:81:in `evaluate'
         from E:/apps/jruby-1.1.5/lib/ruby/1.8/irb/context.rb:219:in `evaluate'
         from E:/apps/jruby-1.1.5/lib/ruby/1.8/irb.rb:150:in `eval_input'
         from E:/apps/jruby-1.1.5/lib/ruby/1.8/irb.rb:259:in `signal_status'
         from E:/apps/jruby-1.1.5/lib/ruby/1.8/irb.rb:147:in `eval_input'
         from E:/apps/jruby-1.1.5/lib/ruby/1.8/irb/ruby-lex.rb:244:in `each_top_level_statement'
         from E:/apps/jruby-1.1.5/lib/ruby/1.8/irb/ruby-lex.rb:230:in `loop'
         from E:/apps/jruby-1.1.5/lib/ruby/1.8/irb/ruby-lex.rb:230:in `each_top_level_statement'
         from E:/apps/jruby-1.1.5/lib/ruby/1.8/irb/ruby-lex.rb:229:in `catch'
         from E:/apps/jruby-1.1.5/lib/ruby/1.8/irb/ruby-lex.rb:229:in `each_top_level_statement'
         from E:/apps/jruby-1.1.5/lib/ruby/1.8/irb.rb:146:in `eval_input'
         from E:/apps/jruby-1.1.5/lib/ruby/1.8/irb.rb:70:in `start'
         from E:/apps/jruby-1.1.5/lib/ruby/1.8/irb.rb:69:in `catch'
         from E:/apps/jruby-1.1.5/lib/ruby/1.8/irb.rb:69:in `start'
         from E:\apps\jruby-1.1.5\bin\jirb:19Maybe IRB bug!!</pre>
<p>Yikes. I&#8217;ve been reading Java stack traces for seven years, but I really have no idea what this error message is telling me. If I honestly thought that line of code should work, or was tired and trying to meet a deadline, this stack trace would be anything but helpful to me.</p>
<p>Just to compare things a bit, I tried to same line of code in the 1.5.6 version of <strong>groovysh</strong>, which is the interactive interpreter for Groovy:</p>
<pre> groovy:000&gt; 100 -= 43
 ERROR org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed, groovysh_evaluate: 2:
 [100] is a constant expression, but it should be a variable expression at line:
 2 column: 5. File: groovysh_evaluate @ line 2, column 5.
 1 error</pre>
<p>Ok, still a little confusing, but much easier to follow. Basically, it&#8217;s telling me that &#8220;100&#8243; should be a variable of some type instead of a literal. That makes sense.</p>
<p>I thought this might be an anomaly, and I wanted to give Jruby another shot, so I tried executing the next &#8220;broken&#8221; line of code from the book in both jirb and groovysh:</p>
<pre> (1 + 3) * 2 + 1)</pre>
<p>First, let&#8217;s try it in Jruby:</p>
<pre> irb(main):002:0&gt; (1 + 3) * 2 + 1)
 SyntaxError: (irb):3: , unexpected tRPAREN

         from E:/apps/jruby-1.1.5/lib/ruby/1.8/irb/workspace.rb:81:in `irb_binding'
         from E:/apps/jruby-1.1.5/lib/ruby/1.8/irb/workspace.rb:53:in `eval'
         from E:/apps/jruby-1.1.5/lib/ruby/1.8/irb/workspace.rb:81:in `evaluate'
         from E:/apps/jruby-1.1.5/lib/ruby/1.8/irb/context.rb:219:in `evaluate'
         from E:/apps/jruby-1.1.5/lib/ruby/1.8/irb.rb:150:in `eval_input'
         from E:/apps/jruby-1.1.5/lib/ruby/1.8/irb.rb:259:in `signal_status'
         from E:/apps/jruby-1.1.5/lib/ruby/1.8/irb.rb:147:in `eval_input'
         from E:/apps/jruby-1.1.5/lib/ruby/1.8/irb/ruby-lex.rb:244:in `each_top_level_statement'
         from E:/apps/jruby-1.1.5/lib/ruby/1.8/irb/ruby-lex.rb:230:in `loop'
         from E:/apps/jruby-1.1.5/lib/ruby/1.8/irb/ruby-lex.rb:230:in `each_top_level_statement'
         from E:/apps/jruby-1.1.5/lib/ruby/1.8/irb/ruby-lex.rb:229:in `catch'
         from E:/apps/jruby-1.1.5/lib/ruby/1.8/irb/ruby-lex.rb:229:in `each_top_level_statement'
         from E:/apps/jruby-1.1.5/lib/ruby/1.8/irb.rb:146:in `eval_input'
         from E:/apps/jruby-1.1.5/lib/ruby/1.8/irb.rb:70:in `start'
         from E:/apps/jruby-1.1.5/lib/ruby/1.8/irb.rb:69:in `catch'
         from E:/apps/jruby-1.1.5/lib/ruby/1.8/irb.rb:69:in `start'
         from E:\apps\jruby-1.1.5\bin\jirb:19Maybe IRB bug!!</pre>
<p>Ok, again, this is complete giberish. What the heck&#8217;s a tRPAREN? Ok, now let&#8217;s try it using groovysh:</p>
<pre> groovy:000&gt; (1 + 3) * 2 + 1)
 ERROR org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed,
 groovysh_parse: 1: unexpected token: ) @ line 1, column 16.
     (1 + 3) * 2 + 1)
                    ^</pre>
<p>Ok, this is <em>exactly</em> what I hoped to see. A nice, clear message telling me what I forgot and what it is associated with.</p>
<h3>Shortest. Evaluation. Ever</h3>
<p>You may not be saying that this is a weird way to evaluate a language. Well, it wasn&#8217;t my plan to evaluate Jruby by looking at its error messages, but it was all that I guess I needed. Here&#8217;s why error message quality is important to me:</p>
<ol class="decimal">
<li>Based on my experiences with numerous up-and-coming scripting languages, the quality of the error messages is proportional to the quality of the interpreter. If this assumption is true in this case, then the Groovy interpreter still appears to be more mature than the Jruby interpreter.</li>
<li>Other programmers won&#8217;t know what to do when they see one of the Jruby stack traces. Even if I was able to train myself to read the Jruby stack traces, I doubt that my co-workers would have the time or inclination to follow suit.</li>
</ol>
<p>So, once again, when it comes to my unusual needs, Groovy wins the battle of stability and ease-of-use. Before I end this post, however, I would like to say a few good things about Jruby so that I don&#8217;t appear to be partisan:</p>
<ul class="circle">
<li>I&#8217;m really happy that Jruby finally has a tool that will compile your .rb files into .class files. This will make it much easier for me to deploy Jruby applications in my environment some day.</li>
<li>Jruby seems to be improving at a rapid pace, and it has a lot of support from companies such as Sun. I think that it will be stable enough for my needs within a year or so.</li>
</ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/tompurl.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/tompurl.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/tompurl.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/tompurl.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/tompurl.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/tompurl.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/tompurl.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/tompurl.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/tompurl.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/tompurl.wordpress.com/9/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tompurl.com&blog=3216699&post=9&subd=tompurl&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://tompurl.com/2008/11/13/jruby-vs-groovy-for-administrative-scripting/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7b972ff5d62434623ade7ad88b02aa99?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">tpurl</media:title>
		</media:content>
	</item>
	</channel>
</rss>