Showing posts with label development. Show all posts
Showing posts with label development. Show all posts

Sunday, April 11, 2010

Installing .NET development support

Previous: Installing Tomcat (partial FAIL)

I'm not actively working on a mono project at the moment, so I didn't spend too much time configuring a development environment. Actually, I didn't spend any time configuring a development environment. I installed the basic tools with these commands:

sudo apt-get install
mono-devel
libmono-winforms2.0-cil
monodevelop
monodevelop-nunit
monodevelop-debugger-mdb

If you're interested, my notes about getting started with these tools are in this post: http://kotowanandesu.blogspot.com/2009/08/installing-support-for-net.html.

Next: Restoring Firefox personalization after re-installing Ubuntu

Sunday, November 15, 2009

Installing Wubi on Acer Netbook

Previous: Firefox addon toolbar buttons not displayed

I've been using my Toshiba Satellite as my main workhorse, and my Acer Netbook as a system for running presentations at conferences and user group meetings and for clients. I took only the Acer with me on a business trip recently, and I became quite frustrated with using Windows XP all the time, rather than just for running presentations. Besides that, I missed having the usual tools available. I decided to load Ubuntu Linux on the Acer so I would have similar environments on both machines, and to avoid the hassle of using Windows.

I have a conventional dual-boot setup on the Toshiba. For the Acer, I decided to try Wubi, a program for Microsoft Windows that manages an Ubuntu dual boot for you, without your having to repartition the hard drive manually. I wanted to see how the user experience compares with the conventional dual boot setup.

Wubi install



First, I went to http://wubi-installer.org/ and downloaded the Wubi installer.

Next, I started Windows XP on the Acer and ran the installer, following the prompts as needed. Everything went smoothly.

After rebooting into Ubuntu Linux, Wubi copied the basic installation files and set up its pseudo partition. It installed 9.10 Karmic.

Making Ubuntu the default OS on boot



By default, Wubi has Windows as the default OS. To change that, here is what I did:

1. Boot into Windows XP.

2. Go to Control Panel

3. Switch to Classic View

4. Choose: System -> Advanced -> Startup and Recovery

5. From "Default Operating System" drop-down list, choose "Ubuntu"

6. Click OK on all open dialog windows to close them

Ubuntu upgrade



From there, I followed my own instructions for updating the system and loading the various programs I use, starting with this blog post: http://kotowanandesu.blogspot.com/2009/08/updating-ubuntu.html. The system upgrade went smoothly.

Ruby development support



The next step was to install support for ruby development. I followed the steps I had documented previously in this post: http://kotowanandesu.blogspot.com/2009/08/installing-support-for-ruby.html.

Things had changed a bit since I installed 9.04. Here are the differences I encountered:

1. When I ran the command
sudo apt-get install libmysql-ruby libmysqlclient-dev
the virtual package name libmysqlclient-dev was resolved automatically and the correct components were installed without the need for any additional action on my part.

2. When I installed the ruby bindings for MySQL, the software installed correctly but the ri documentation was missing a lot of bits and pieces. I did not consider this a serious problem.

3. The menu option Applications -> Add/Remove Applications was replaced by Ubuntu Software Center. I discovered that when I started to type the name of an application into the search box, it auto-filled all matching names. This was faster than the old way of finding the packages I wanted.

No problems with the rest of the ruby-related stuff, except some of the ri docs for nokogiri were missing. For the scripts and aliases documented in the original blog post, I just copied the files from the Toshiba laptop.

Java development support



I followed the instructions I had documented earlier in this post: http://kotowanandesu.blogspot.com/2009/08/installing-support-for-java.html. Everything worked the same as the first time, with the following exceptions:

1. Eclipse Galileo was installed by default. No additional steps were needed on my part.

2. Previously, Eclipse installed with a default value for the classpath variable M2_REPO. This time, it had no default definition. In Eclipse, under Window -> Preferences -> Java -> Build Path -> Classpath Variables, I added M2_REPO to point to /home/dave/.m2.

3. This time, migrating my existing projects to the new instance of Ubuntu was easier, since I was copying them from another Ubuntu instance that was configured in the same way. The first time around, I copied project files from an OS X system that was configured a bit differently.

Tomcat install



I had some difficulty with the standard installation procedure the first time around, as described in this post: http://kotowanandesu.blogspot.com/2009/08/installing-tomcat.html. This time, I checked for updated documentation and found this information about installing Tomcat 6 on Ubuntu 9.10: https://help.ubuntu.com/9.10/serverguide/C/tomcat.html. Per that documentation, I ran the command
sudo apt-get install tomcat6
and the It Works! page came up fine.

ColdFusion install



I skipped the ColdFusion installation for the moment, since I wouldn't need it in the near future.

.NET support



As before (see http://kotowanandesu.blogspot.com/2009/08/installing-support-for-net.html), I entered the command
sudo apt-get install mono-devel


To install the IDE, used Ubuntu Software Center, and then found it under Applications -> Programming. Go figure. I didn't try the Hello, World! programs this time, because I'm confident in the package.

The NUnit and debugger installs went smoothly.

Git install



The git install went smoothly, as documented here: http://kotowanandesu.blogspot.com/2009/08/installing-git.html.

eXPlainPMT install



I skipped this install, since I've started using the Kanban approach rather than the iterative approach on personal development projects.

Firefox development add-ons



I skipped this, since I won't be using the Acer as my primary development platform.

...and the rest of it



All that remained was to copy files from the Toshiba to the Acer. Up and running!

Next: Flash player for Firefox libnspr4-dev dependency

Sunday, August 16, 2009

Firefox web development add-ons

Previous: Installing eXPlainPMT

Upgraded Firefox


Ubuntu came with Firefox 3.0.2 pre-installed. To upgrade it, I typed 'apt:firefox-3.5' in the Firefox location field. This is a front-end to Synaptic Package Manager that was added to Firefox for the Ubuntu distro.

This installed Firefox 3.5.2 and added an entry in the Applications -> Internet menu named 'Shiretoko Web Browser' (the codename for Firefox 3.5).

On starting the new browser, I saw that it had transferred my bookmarks correctly. However, it did not find a compatible version of Ubuntu Firefox Extensions. I typed 'apt:' and 'apt:firefox-3.5' into the location field and it complained about the protocol name. Maybe this handy feature is gone!

Add-ons for web development


I browsed to https://addons.mozilla.org/en-US/firefox/ and selected the following add-ons (selected all before restarting Firefox):
  • Abduction!
  • Bottom Error Console
  • ColorZilla
  • Console2
  • Dom Inspector
  • EditCSS
  • Execute JS
  • Firebug
  • lori (Life-of-request info)
  • QuickRestart
  • SQL Injection
  • SQLite Manager
  • Web Developer
  • XSL Results

The current version of Html Validator was not available on the Mozilla add-on site on the date when I was installing add-ons. The version on the developer's site at http://users.skynet.be/mgueury/mozilla/ turned out to be incompatible with Shiretoko. Too bad, since this one does validation locally in the browser and does not depend on any third-party sites.

The current version of Selenium IDE was not available on the Mozilla site. I installed it from "Selenium HQ" at http://seleniumhq.org/download/. The install worked fine.

Next: Making Vista liveable

Thursday, August 13, 2009

Installing support for .NET development

This is a follow-up from Installing support for ColdFusion development.

Fair warning: This is not a definitive tutorial, it's just an informal record of my experiences in trying to install software for .NET development on Ubuntu. I had not done any .NET development prior to this. Maybe in a future blog post I'll have something more interesting to share.

.NET development is supported on Linux by the Open Source project mono, at http://www.mono-project.com. In reading about this on the web, I learned that the Ubuntu distro includes support for running .NET applications with mono, but not for developing them. My first step, then, was to install the basic mono package:
sudo apt-get install mono-devel
To verify the installation worked, I followed the instructions at http://www.mono-project.com/Mono_Basics to compile and run a few simple Hello World programs.

The first is a command-line Hello World that looks like this:
using System;

public class HelloWorld
{
static public void Main ()
{
Console.WriteLine ("Hello Mono World");
}

}
To produce a .NET 2.0 assembly, I compiled with
gmcs hello1.cs
No errors reported. To execute the program, I used
mono hello1.exe
It worked fine.

BTW this was my first-ever C# program. I'm so proud! :-) Oh, wait. I didn't test-drive it. I'm so ashamed. :-(

The second test was a gtk# version of the same thing. It looks like this:
using Gtk;
using System;

class Hello {

static void Main()
{
Application.Init ();

Window window = new Window ("helloworld");
window.Show();

Application.Run ();

}
}
and is compiled like this:
gmcs hello2.cs -pkg:gtk-sharp-2.0
I ran it with
mono hello2.exe
and it worked fine.

Next there was a Winforms sample. It looks like this:
using System;
using System.Windows.Forms;

public class HelloWorld : Form
{
static public void Main ()
{
Application.Run (new HelloWorld ());
}

public HelloWorld ()
{
Text = "Hello Mono World";
}
}
I compiled it according to the instructions with this command:
gmcs hello3.cs -pkg:dotnet
This one didn't go quite so well. It complained about 13 missing dlls.

I found a suggestion at http://code.google.com/p/paint-mono/issues/detail?id=6 to try this:
sudo apt-get install libmono-winforms2.0-cil
and compile with
gmcs hello3.cs -r:System.Windows.Forms.dll
This time the compile worked. I tried running the program with
mono hello3.exe
and it worked fine.

So at that point I had at least a partial installation of basic mono development tools. Clearly, there were still missing pieces, but at the time I did not know what more to look for.

MonoDevelop IDE


This is an IDE for working with mono. The home page is http://www.monodevelop.com. I installed it with
sudo apt-get install monodevelop
Mono Develop appeared under Applications -> Programming and it started up nicely. I didn't know what more to check, so I declared victory and moved on.

NUnit (unit testing tool)


I didn't find any useful help on the NUnit site at http://www.nunit.org, so I searched the web and found some help at stackoverflow.com/questions/924239/what-the-best-setup-latest-mono-monodevelop-on-ubuntu-9-04. They suggested this:
sudo apt-get install
monodevelop-nunit monodevelop-debugger-mdb
As far as I could tell, this appeared to work.

NUnit with MonoDevelop


I had to search for help with this, as well. There doesn't seem to be any single comprehensive source of "getting started" information for people who want to learn to work with mono. At http://www.dijksterhuis.org/using-nunit-with-monodevelop/ Martijn Dijksterhuis suggests the following.

First, create a new Solution in MonoDevelop. I chose Console Project and skipped the options presented in the Project Features dialog. Then, right-click the References item in the Solution tree menu in the left-hand pane. Choose Edit References and select NUnit.Core and NUnit.Framework to include them in the Solution. What I found at that point were two options named nunit.core (all lower case) and two options named nunit.framework. One of each had a version number. I chose the entries that had version numbers.

Next step was to paste in the sample program Martijn had posted:
using System;
using NUnit.Framework;

namespace bank
{
public class Account
{
private float balance;
public void Deposit(float amount)
{
balance += amount;
}

public void Withdraw(float amount)
{
balance -= amount;
}

public void TransferFunds(Account destination, float amount)
{
}

public float Balance
{
get { return balance; }
}
}
}

namespace bank
{
[TestFixture]
public class AccountTest
{
[Test]
public void TransferFunds()
{
Account source = new Account();
source.Deposit(200.00F);
Account destination = new Account();
destination.Deposit(150.00F);

source.TransferFunds(destination, 100.00F);
Assert.AreEqual(250.00F, destination.Balance);
Assert.AreEqual(100.00F, source.Balance);

}

[Test]
public void DepositFunds()
{
Account source = new Account();
source.Deposit(200.00F);
Assert.AreEqual(200.00F, source.Balance);
}

}
}

namespace UnitTestDemo
{
public class MyAccountingSoftware
{

public static void Main()
{
bank.Account DemoAccount = new bank.Account();
DemoAccount.Deposit(1000.00F);
DemoAccount.Withdraw(500.50F);
Console.WriteLine("Our account balance is {0}", DemoAccount.Balance);
}

}
}
I chose View -> Unit Tests from the MonoDevelop menubar and right-clicked my Solution, then chose View -> Test Results to see the results. It appeared as if NUnit ran, and the sample program had 1 passing and 1 failing test. Looked good enough as a start.

Next: Pimp My Instiki

Installing support for ColdFusion development

Previous: Installing Tomcat.

I wanted to set up a ColdFusion development environment similar to that used at a current client of mine. That environment is based on ColdFusion, ColdSpring, ModelGlue, and MXUnit. The software used in this set-up is:
  • Eclipse - development IDE
  • ColdFusion - the base product
  • ColdFusion Eclipse Plugin - Eclipse support for ColdFusion development
  • ColdFusion ModelGlue - an MVC framework for webapps
  • ColdSpring - a Spring-like IoC implementation for ColdFusion
  • MXUnit - a unit test framework for ColdFusion, based on JUnit
  • CFEclipse Plugin - Eclipse support for CFML
  • MXUnit Eclipse Plugin - Eclipse support for MXUnit

ColdFusion


I followed instructions on http://www.adobe.com to download and install ColdFusion Developer Edition.
  1. Navigate to the ColdFusion product page on Adobe's website: http://www.adobe.com/products/coldfusion/.

  2. Follow the link labeled Download the free Developer Edition.

  3. Sign in to the Adobe site. Create a userid and password if you don't already have one. Don't worry, it's harmless.

  4. From the drop-down list for ColdFusion Developer Edition, choose the appropriate language and operating system.

  5. Click the button labeled Download next to the Developer Edition drop-down box.

  6. I copied the downloaded file, which is an installation program, to an "installation" directory, gave myself execution permission on it, and ran it. I followed the prompts to install a standalone ColdFusion server with a root directory of /home/dave/coldfusion8, to listen on port 8500.

  7. Started ColdFusion with
    sudo ./coldfusion8/bin/coldfusion start
    and navigated in Firefox to localhost:8500. (Yeah, you read that right: You need root privileges to start a single-user development server on your own machine. That's "enterprise" software, for ya. <sigh>) It told me no application was configured to respond to the request. I tried localhost:8500/CFIDE (based on what I saw in ~/coldfusion8/wwwroot, and not because I knew what I was doing) and it displayed a directory listing of wwwroot/CFIDE. I clicked on administrator and the ColdFusion Administrator app started up. It accepted the password I had defined during the installation process, and appeared to be working. I took this to mean a crude install of the base product had been accomplished. I looked, but couldn't find a sample app. Often, vendors include a sample app you can attempt to run, so that you can see whether the product installed correctly. No such luck here. If there are problems, I suppose they will turn up as I continue configuring the environment.

Install ColdSpring


ColdSpring is a port of Spring to ColdFusion. Its main features are support for IoC and AOP. I obtained it from http://www.coldspringframework.org/. The site offers a quick start guide, a reference guide, and API docs for CFCs. The simplicity and clarity of the packaging and documentation were a refreshing contrast to the "enterprisey" organization and packaging of ColdFusion itself.

I downloaded the pdf Reference Guide. The guide states you can install ColdSpring by placing the source in the web root directory. I learned the hard way that they should have said to unpack the distribution archive in the web root directory. "Place the source" there didn't imply that to me.

There is more than merely a problem with wording, though. While the Reference Guide says you can either place the source in wwwroot or define mappings in Administrator, in fact you must do both. After I defined a mapping for /coldspring to wwwroot, the quickstart app worked. The other sample apps did not work. This tells me the basic install is okay, and there are some configuration secrets that the developers and supporters of ColdSpring think are too obvious to bear mentioning. I'll have to seek help to complete the configuration later, when I'm ready to try using these tools.

Install ModelGlue


ModelGlue is a Model-View-Container framework that comes in ColdFusion and Flex flavors. I downloaded a zipped distribution archive from http://www.modelglue.org. At first glance, the documentation at http://docs.model-glue.com/ looks comprehensive, well-organized, and filled with concrete, practical examples, tutorials, and how-tos. One exceptionally good feature of the documentation is that the main heading on the first page reads, "Don't panic!" The site also has installation and configuration instructions, which I followed more-or-less like this:
  1. Unpack the distribution archive
  2. Copy the ModelGlue folder to ColdFusion's wwwroot folder

Install MXUnit


MXUnit is a unit testing framework based on JUnit. To get it, I went to http://www.mxunit.org/ and downloaded the distribution archive. Then I unpacked it in the coldfusion8/wwwroot directory.

To verify the installation, I started the ColdFusion server and went to http://localhost:8500/mxunit/index.cfm. It ran a trivial sample app and displayed a "Congratulations" message.

So far, so good with the ColdFusion setup.

Install the CFEclipse Eclipse Plugin


This is an Eclipse plugin that provides language support for ColdFusion Markup Language (CFML). The CFEclipse wiki has current information about the Eclipse update site, recent versions, known problems and workarounds. When I installed it, the update site was www.cfeclipse.org/update. Installation instructions are at http://trac.cfeclipse.org/wiki/InstallingCfeclipse. I followed the instructions more-or-less this way:
  1. Started Eclipse
  2. From the main menu, chose Help -> Install New Software...
  3. In the Install dialog window, clicked the Add button. Entered 'CFEclipse' in Name and 'http://www.cfeclipse.org/update' in Location. Clicked OK.
  4. Eclipse displayed two downloadable items, the editor and the documentation. I checked both. I also unchecked the 'group items by category' box and clicked Next. This resulted in an error, apparently because it tried to grab the documentation for Eclipse 3.4 and 3.5. I only needed 3.5, so I deselected the documentation for 3.4 and tried again. It seemed to like this better.
  5. Clicked Next on the 'review' dialog.
  6. On the 'accept licenses' dialog, clicked the 'accept' radio button but the installation did not work. The Next and Finish buttons remained disabled. I tried checking 'do not accept', scrolling from top to bottom of each license, and then checking 'accept' on each one. This time, the Finish button became enabled.
  7. Eclipse called for a restart, and I clicked Yes to restart it.
Since I have no existing ColdFusion code and no ColdFusion experience, I didn't try to write a test app. I noticed that when I opened the perspectives dialog, there was an entry for CFEclipse. I chose it and things looked pretty normal.

Install the MXUnit Eclipse Plugin


The installation instructions at http://www.mxunit.org/doc/index.cfm?doc=installplugin appear to be designed for an earlier version of Eclipse and for Microsoft Windows. It looks like a standard Eclipse software update, so I used the information from the site but followed a procedure like the one I used for the CFEclipse Plugin. The update site is http://mxunit.org/update. This installed MXUnit Test Runner.

At this point I believed I had a working installation of the ColdFusion development tools my client uses.

Next: Installing support for .NET development.

Installing Tomcat

Previous: Installing Tomcat - FAIL!

I went to http://tomcat.apache.org and downloaded a zipped archive of Tomcat. I unpacked it into my home directory, resulting in a directory tree starting with apache-tomcat-x.x.x. I renamed the top-level directory tomcat-dev.

In Terminal I changed to the tomcat-dev/bin directory and granted execute permission on everything in it with
chmod +x *
Then I tried starting Tomcat with
startup.sh
I expected this to start a server listening on port 8080. It worked.

I edited conf/server.xml and set the connection port to 8081. I edited conf/tomcat-users.xml to define a user like this

<role rolename="manager"/>
<role rolename="tomcat"/>
<user username="tomcat" password="tomcat" roles="tomcat,manager"/>
</tomcat-users>
Tomcat started properly on 8081, and I could get to the Manager app.

Next: Installing support for ColdFusion development

Installing Tomcat - FAIL!

Previous: Installing support for Java development

Installing Tomcat should be routine. I've done it many times on Windows and OS X systems. Installing it on Ubuntu turned out to be a lengthy and frustrating experience.

The Ubuntu help pages have a description of how to install Tomcat system-wide or on a per-user basis for a development environment; see https://help.ubuntu.com/8.10/serverguide/C/tomcat.html.

I followed the instructions provided on that page under Using private instances. The commands to install Tomcat and to create a user-specific instance were:
sudo apt-get install tomcat6-user
tomcat6-instance-create my-instance
This resulted in a Tomcat installation under ~/my-instance. I'm not crazy about that directory name. Before changing it, I wanted to verify the installation was okay so far. I checked my-instance/conf/server.xml and saw it was set to listen on port 8080, so I left it alone. I ran this command:
my-instance/bin/startup.sh
Browsing to localhost:8080 in Firefox got me a blank document. I tried localhost:8080/manager and got a blank document. I tried localhost:8080/tomcat and got a blank document. In my-instance/logs, both catalina.out and the log file indicated startup was normal, services started properly, and showed no other activity and no errors. I had not seen this behavior in a Tomcat installation before.

I edited my-instance/conf/server.xml and changed the connector port to 8088, then tried it again. Same behavior. The documentation states that no webapps are deployed by default. That might be the reason it serves nothing but blank documents. Apparently, the manager app is not included in the per-user package. Normally, I expect to see the "It works!" message by default.

My next thought was to download the manager application by itself and drop it into the webapps directory. All the documentation I could find stated that the manager application is included by default in Tomcat installations. Clearly, this is not the case for the user-specific Ubuntu package.

The Ubuntu Tomcat help page listed this command to install the manager application, assuming you had installed the service version of Tomcat. It looked as if this might do the trick:
sudo apt-get install tomcat6-admin
Unfortunately, this resulted in a Tomcat service automatically installing and starting.

It was unclear how to shut the thing down manually. I found a posting online that indicated the start and stop commands are in /etc/init.d. I ran
/etc/init.d/tomcat6 stop
to shut down the instance. I was unable to locate a .war file for the manager app anywhere.

A task that should have taken me five minutes had now extended into hours. I had to stop and go to work. Before I gave up for the morning, I found a backup copy of another Tomcat installation on an external hard drive. I was thinking of copying the manager and host-manager applications from there to the user-specific Tomcat installation on Ubuntu, but on reflection I realized this was not a repeatable or reliable way to install software.

I decided to install dev instances of Tomcat the "old-fashioned way."

Next: Installing Tomcat

Installing support for Java development

Previous: Installing support for Ruby development.

Basic software installs


I installed the Java development tools, Eclipse, and Maven with these commands:
sudo apt-get install sun-java6-jdk
sun-java6-plugin maven2 eclipse
To check which version of Java was the default after the install, I ran
java -version
It displayed 1.5.0, so I ran this command to set version 6 as the default:
sudo update-java-alternatives -s java-6-sun
After that when I ran java -version it came back with 1.6.0.

To verify maven2 was installed correctly, I ran the following command:
mvn --version
No problems at this point.

To verify Eclipse was installed correctly, I went to the Applications -> Programming on the main menubar and saw there was an entry for Eclipse. I selected it, saw that it started, and exited. I noticed the version was 3.2. I will check into getting a more recent version later.

Maven configuration


Although maven2 appeared to have installed correctly, I was unable to locate the local repo or the maven home directory or any environment variable settings pertaining to maven. A quick web search failed to turn up any useful information about the default location where apt-get installs maven2.

As far as I could tell, being a n00b and all, the environment variables maven2 supposedly needs to be set were not set, and there was no local repo. I decided to try
mvn archetype:generate
just to see whether it would do anything or complain about missing components or unknown paths or whatever. I chose quickstart when prompted, and it worked perfectly. It also created .m2/repository as it downloaded dependencies. Nice to know.

Upgrading Eclipse to 3.5 "Galileo"


At the time I installed it, the latest Eclipse release wasn't yet included in the Ubuntu distro. John Paulett provides a nice set of instructions for installing it on Ubuntu 9.04 on his site at http://johnpaulett.com/2009/06/26/install-eclipse-galileo-3-5-on-ubuntu-jaunty-9-04/. Using his instructions as a guide, this is how I installed Eclipse 3.5:
  1. Created a directory for Eclipse under /home. John recommends ~/bin/packages/eclipse, and he later installs Galileo in ~/bin/packages/eclipse/eclipse3.5 because he needs multiple versions of Eclipse. I don't need multiple versions, so I installed it in ~/bin/packages.
    cd ~/bin
    mkdir packages
  2. Downloaded the 64-bit version of Eclipse 3.5 (long lines are broken for readability in Blogger):
    cd packages
    wget http://d2u376ub0heus3.cloudfront.net/galileo/
    eclipse-java-galileo-linux-gtk-x86_64.tar.gz
  3. Next, I unpacked the archive in place, in the packages directory:
    tar xzvf eclipse-java-galileo-linux-gtk*.tar.gz
  4. I deviated from John's instructions at this point, and just updated /usr/share/applications/eclipse.desktop to point to the executable I had just installed:
    Exec=/home/dave/bin/packages/eclipse/eclipse

I started Eclipse from the main menu, Applications -> Programming -> Eclipse, and it started the new Galileo version. Eclipse had no trouble opening one of the workspaces I had copied over from my OS X system.

Eclipse configuration


I set the M2_REPO classpath variable in Eclipse to point to the local repo. I started Eclipse and navigated to Window -> Preferences, then expanded the tree menu items Java -> Build Path -> Classpath Variables.

I noticed that this version of Eclipse comes with an M2_REPO already defined. It points to the default location of /Users/dave/.m2. Then I chose Edit and changed the value to /home/dave/.m2.

Migrating Java development projects


I copied my ~/.m2/repository from the MacBook Pro to an external drive, and then from there merged it with the ~/.m2/repository on Ubuntu.

I copied my eclipse-workspaces directory from the MacBook Pro to the external drive, and from there to the ~/projects directory on Ubuntu.

Next step was to try and build the projects I'm currently working on to discover what configuration options I would have to change to get things working on the new system. I've been around the block too many times to expect things to "just work." Somewhere, something must be pointing to a resource that doesn't exist on the new system, or depends on a different version of something than the one I've installed. I decided to try building a Function Point Analysis application I'd been working on last year. It's a good test case for maven2 because it's got multiple components and a hierarchy of POMs.

I was surprised and pleased when mvn compile worked on the first try. I ran mvn test and got two failures out of many, many tests. Old, dusty neurons fired, reminding me that these tests used to fail with maven on my old system, too. They worked under Eclipse. So it was time to see if Eclipse would "just work," too. Wouldn't that be nice? Sure it would. Actually, I knew it wouldn't work because I needed to change the build dependencies in Eclipse to reflect their new locations. But I could at least see that no other, unexpected errors occurred.

The project would not build inside Eclipse because references to external libraries were invalid. I expected this, since I had set things up differently on OS X. I knew I would have to redefine a few things with the new setup. I was satisfied that things were in place and would work. There was just some housekeeping to do since I had decided to organize the files differently on the new system. Java was good to go!

Next: Installing Tomcat - FAIL!

Wednesday, August 12, 2009

Installing support for Ruby development

Previous: Updating Ubuntu.

Ruby


To install Ruby support:
sudo apt-get install ruby-full

Geany (an IDE)


Low let's get Geany, a rudimentary IDE I find handy for Ruby development.
sudo apt-get install geany

Gems (to install other Ruby packages)


This installation procedure is a little different from the usual apt-get thing.

1. Look on Ruby Forge and see what the latest version of Ruby Gems is: http://rubyforge.org/frs/?group_id=126. Hover over the .tgz filename to see the correct URL for the wget command.

2. The Ruby community does not recommend using apt-get to install Ruby Gems because Advanced Package Tool and gems may get out of sync about versions. The recommended way is to open a Terminal window and enter the following commands (in this case the version I found in step 1 was 1.3.4). Long lines are split for readability in Blogger. Use common sense.
cd ~
wget http://rubyforge.org/frs/download.php/57643/
rubygems-1.3.4.tgz
tar xzvf rubygems-1.3.4.tgz
cd rubygems-1.3.4
sudo ruby setup.rb
3. Note which executable was installed (a message appears near the end of the installation) and define a symlink to it. In this case it was version 1.8.
sudo ln -s /usr/bin/gem1.8 /usr/bin/gem
4. If the installation worked, the following command will display version information. In this case we want to see "1.3.4". By changing directories first I help myself believe the PATH was updated. I hear it's good to believe.
cd
gem -v

MySQL server


I use MySQL for Ruby on Rails development (and other things, too). To install:
sudo apt-get install mysql-server
Of course, you should set the MySQL root password to something other than "empty" when prompted. The installer starts mysqld. To be sure it worked, run
ps ax | grep mysql
and look for /var/run/mysqld/mysqld.pid.

After installation, you can stop and start MySQL through System -> Administration -> Services on the main menubar. Alternatively, you can start and stop MySQL from a Terminal window using the commands:
sudo /etc/init.d/mysql start
and
sudo /etc/init.d/mysql stop

MySQL GUI client


To install a gui client for MySQL, choose Applications -> Add/Remove Applications from the main menubar. If prompted to update the list of available packages, do so. Under Show, choose "All available applications". Select "MySQL Administrator" for a GUI client and "MySQL Query Browser" for a GUI tool for running queries. After the installer finishes, the two applications will appear under Applications -> Programming on the main menubar.

Ruby bindings for MySQL


Open a Terminal window and enter the following commands:
cd ~
sudo apt-get install libmysql-ruby libmysqlclient-dev
The package libmysqlclient-dev is a virtual package. When you run the command above, you will see an error message that shows the name of the real package. Substitute it in the command line and run it again. When I ran it, it showed libmysqlclient15-dev, so I ran the command this way:
sudo apt-get install libmysql-ruby libmysqlclient15-dev
Run this command to build it:
sudo gem install mysql

Rails


Use Gems to install Rails. Open a Terminal window and enter the following command
cd ~
sudo gem install rails
If the installation succeeded, the following command will display version information:
rails -v
Verify the installation by generating a trivial rails app:
cd ~
rails myrailsapp -d mysql
or, for sqlite3:
cd ~
rails myrailsapp
In myrailsapp/script, run the command:
./server
If all is well, a WEBrick server will start and will listen on port 3000 for HTTP requests. Try loading the following URL in a browser. You should see a welcome page.
http://localhost:3000

Testing tools


These are tools for test-driven-, behavior-driven-, and storytest-driven-development:
  • Autotest - continuous testing (part of ZenTest)
  • Cucumber - storytest tool
  • RCov - coverage tool
  • rspec - BDD tool
  • Webrat - browser simulator (used by Cucumber)

On Debian variants (like Ubuntu), you have to install a couple of libraries before installing Webrat. They are needed by Nokogiri, the XML libary used in Webrat.
sudo gem install ZenTest
sudo gem install rcov
sudo gem install rspec rspec-rails
sudo gem install cucumber
sudo apt-get install libxslt1-dev libxml2-dev
sudo gem install webrat

Some conveniences


I'm rather slow-witted, so I find it helpful to follow a few conventions even though I'm the only person working on my system or on my little side projects. I put my software development projects under a directory called /projects. I nearly always use Geany for Ruby on Rails development. I use rspec and Cucumber with these projects. So it's convenient to have a quick way to set up a new Ruby on Rails project in the usual directory that includes the elements I usually want and that creates a Geany project file. To that end, I created a shell script in ~/bin that sets these things up for me. The script newrailsapp looked like this as of the time I posted this information:
#!/bin/bash
if [ -z $1 ]; then
echo "usage: newrailsapp appname"
exit
fi
if [ -e $1 ]; then
echo "Can't create $1 because it already exists. Quitting."
exit
fi

# Create the rails app

rails -d mysql $1

# Generate rspec support for the app

cd $1
./script/generate rspec
./script/generate cucumber

# Create a geany project file for the app

echo "Creating geany project file $1.geany"
cd ..
echo "[indentation]" > $1.geany
echo "indent_width=4" >> $1.geany
echo "indent_type=1" >> $1.geany
echo "indent_hard_tab_width=8" >> $1.geany
echo "detect_indent=false" >> $1.geany
echo "indent_mode=2" >> $1.geany
echo " " >> $1.geany
echo "[project]" >> $1.geany
echo "name=$1" >> $1.geany
echo "base_path=/home/dave/projects/$1/" >> $1.geany
echo "make_in_base_path=false" >> $1.geany
echo " " >> $1.geany
echo "[files]" >> $1.geany
echo "current_page=-1" >> $1.geany
Also created these aliases in ~/.bash_aliases:
# Start Geany (IDE)
alias geany='geany &'
# Start and stop any Rails test server
alias server='script/server &'
alias server_stop='~/bin/server_stop'

The alias geany just starts Geany in the background. Saves a couple of keystrokes.

The purpose of server is to start a Webrick server for dev-testing a Rails app. It's meant to be run from a command line when you're in the appropriate project subdirectory. The server script looks like this:
#!/bin/bash
script/server &
The purpose of server_stop is to stop a Webrick server. It looks like this (with the usual caveat about long lines)
#!/bin/bash
kill -9 `ps -o pid,cmd --no-heading -p $(pgrep ruby)
| grep script/server | awk '{print $1}'`
The assumption is that there will only be one Webrick server running at a time. It's a safe assumption because all of this is set up for a single user environment.

Next: Installing support for Java development