Posts Tagged ‘agile-web-development-with-rails’
Running Depot On Tomcat
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 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 developer to deploy a Jruby-On-Rails application on her workstation. If you want to install Tomcat in a public-facing environment, then you need a different tutorial
Tomcat Installation
Tomcat was my choice for the following reasons:
- It’s very easy to install. Just unpack it and go (if you already have the proper version of Java installed).
- It’s very easy to administer on my netbook (which is where I’m learning about RoR and Jruby).
- It’s relatively lightweight compared to JBoss or WebLogic.
- It’s very easy to deploy war files. Just drop them in
$TOMCAT_HOME/webapps, restart Tomcat, and you’re up-and-running.
So let’s install Tomcat:
$ 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
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:
$ 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
Great, now you can test your installation by pointing your browser at the following url:
- http://localhost:8080
You can also shut the server down using the shutdown.sh script from the same directory.
Packaging Depot In A WAR File
Now that Tomcat is up-and-running, let’s build our WAR file. If you haven’t already installed warbler, then you can do so with the following command:
$ jruby -S gem install warbler
Warbler 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 activerecord-jdbcsqlite3-adapter driver. Here’s how you do that:
- Run the
warble configcommand from the root directory of your project. This command will create theconfig/warble.rbfile. - Add the following line to the newly-created
config/warble.rbfile:config.gems << "activerecord-jdbcsqlite3-adapter"
That’s it! Now you can build your war file:
$ warble
In a minute or so, you should see a file named depot-jruby.war in the root of your project directory. If you need to rebuild you war file, then simply execute the following command:
$ warble war:clean && warble
Deploying On Tomcat
Now we can finally deploy the WAR file to our Tomcat instance. Here’s how I do it on my machine:
$ cd /opt/apache-tomcat-6.0.24 $ cp /home/tom/Dev/ruby/depot-jruby/depot-jruby.war ./webapps $ ./bin/shutdown.sh && ./bin/startup.sh
Then you can test your application by visiting the following URL:
- http://localhost:8080/depot-jruby/store
Conclusion
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.
Review: Agile Development With Rails, 3rd Edition
Agile Web Development with Rails: A Pragmatic Guide by Dave Thomas
My rating: 4 of 5 stars
In general, this book does a fairly good job of helping you create a rails-based application. Part 3 includes some great in-depth information on the topics that are briefly discussed in Part 2.
I only have one real gripe about this book. It packs in lots of topics (e.g. db theory, AJAX, unit testing, security, deployment), but it doesn’t really tell you much about them. Therefore, if you have a problem, then good luck figuring it out using the content in the book.
A good example is the final chapter which covers deployment. The chapter devotes only a few small paragraphs to configuring Apache for passenger. To me, this section was completely useless unless you were already an expert with Apache configuration. I ended that chapter with a broken Apache server and no resources (from the book) to begin fixing it.
Another problem that I had with that chapter is that it really didn’t follow the pattern that the chapters in Part 2 used. In those chapters, the authors would should you how to do something relatively small, show you how to test it, and then provide some troubleshooting information if the task was particularly complex. The deployment chapter gave you a *very brief and generalized* tutorial in each section, and then just assumed that everything went perfectly. It didn’t show you how to test anything, and it didn’t help you troubleshoot any possible problems.
Don’t get me wrong. I know that no book will provide all of the information that I would ever need about a subject, and thank goodness for the internet in these situations. I was just hoping that all of the chapters in a book that I actually bought would provide better information than some person’s blog.
So in general, I guess I would have to say that this was a very good book with some bad chapters that were tacked-on at the end.
Walking With Rails 1 – Setup On Ubuntu
Overview
One of my goals for 2010 is to gain a decent understanding of the Ruby On Rails framework. I don’t think that this knowledge will directly help me with my current job (as a FileNet P8 administrator), but I do think that it will provide some good benefits.
First, learning about something that’s a little bit outside of your comfort zone can often help you with your day-to-day tasks. For example, if you teach yourself the basics of Java development, then you will know how to read a stack trace. Having this knowledge is very important if you want to administer software written in Java.
Also, it’s just fun. Creating something useful out of a few lines of text never ceases to amaze me. Also, I find that learning new technical skills is good for your brain.
Finally, who knows what the future may bring? It never hurts to know as much as you can about popular technologies in general when you work in IT.
So to get started, I purchased a copy of Agile Web Development with Rails, Third Edition from the Pragmatic Programmers’ web site. This book seems to be one of the best for beginners, and I really love that you can buy DRM-free ebooks from the Pragmatic Programmers’ web site.
Installing Ubuntu Packages
So enough background information. Here’s how I set up my system to get started with Rails development. First, I installed all of the necessary software on my Ubuntu 9.10 machine that was available as an Ubuntu package:
sudo apt-get install rails ruby-full rubygems rake mongrel git-core sqlite3
Here’s why I installed more than just the rails and ruby pacakges. When you install Ruby from source on a Linux machine, you get a lot of software. In addition to the Ruby runtime, you get fun tools like irb, rubygems, rdoc, ri, and rake. However, when you install the ruby package on Ubuntu and Debian, you just get the Ruby runtime along with a a couple of libraries. Since I’m lazy efficient guy, I decided to install the ruby-full package instead to save a few keystrokes. Unfortunately, the ruby-full package still doesn’t include rake or rubygems, so I installed those manually.
Mongrel is a developer’s web server that is designed to work very well with Ruby on Rails development. Since I am also impatient, I wanted a web server that would work a little faster than WEBrick.
Finally, I installed git because I wanted to share code between two different computers. Git is a version control system that is very popular with Ruby developers, so I figured that I would use the most popular Ruby-related tools while I’m learning about Ruby.
Installing Software Without apt-get
Natrually, you can’t install everything that you need with apt-get. For starters, the version of rails that is used in Agile Web Development with Rails, Third Edition is 2.2.2, so let’s install that using rubygems:
sudo gem install rails --version 2.2.2
This operation took a little while (~ 7 minutes) on my machine for some reason.
Note: For some reason, this bog
Next, I’m a Vim user, so I would like to see if the rails.vim plugin would help me at all. There is an official Ubuntu package for this plugin called vim-rails, but when I try to install it using apt-get, I get the following error:
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:The following packages have unmet dependencies:
vim-rails: Depends: vim-full but it is not installable
E: Broken packages
When I tried to install the vim-full package on my machine, I got this error:
Package vim-full is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
E: Package vim-full has no installation candidate
Ok, so after all of that, let’s just install it the easy way:
(Download the latest version of rails.zip from the rails.vim download page)
$ cp rails.zip ~/.vim$ cd ~/.vim$ unzip rails.zip
Finally, open vim or gvim and execute the following command:
:helptags ~/.vim/doc
In case your interested, here are the other Vim-related packages that I have installed on my machine:
- vim-common
- vim-gnome
- vim-gui-commom
- vim-runtime
- vim-tiny
Conclusion
And that’s it! I now appear to have everything that I need to complete the beginning examples in Agile Web Development with Rails using Ubuntu 9.10 and Vim.
Update (1/20/10) – I added the sqlite3 package to the apt-get line above. This package is necessary if you want to query your database manually.

