Greener Fonts???

I read an article today that claims that Century Gothic uses 30% less ink than Arial.

Ink is a big expense in my household. If changing the fonts in the documents that I print can save me money then it is definitely worth while to make this simple change. I will also have fewer cartridges hanging around waiting to be refilled or recycled (why are those recycle envelopes so hard to come by?), and I will cause less pollution in a very teeny tiny way.

The article just mentions email. For me, changing my Firefox fonts will have the biggest impact.

Personal Connections

Waikiki dawn

Waikiki dawn

When I heard about a Aloha on Rails, I jumped on the chance to attend a local conference. Having been to several JavaOne conferences, I knew how helpful they were they were for learning best practices, discovering what people were adopting, and getting a view of what’s coming down the pike. I definitely got all of that, but I unexpectedly took away a lot more.

For one, it was my first “local” conference (well it is an airplane ride away, but it still felt local to me). I was happy to find that about half the people I talked to are developers in Hawaii and a lot of business cards were exchanged with the hope that we could all meet again at Aloha on Rails 2.

Second, it was a small conference. After the first day and a nice pau hana party put on by Agathon Group (thanks guys), everyone was starting to look familiar and we were having great discussions. The theme of the conference was talk story, and that definitely was going on both in the conference rooms and outside. Small conferences also mean that the speakers are easily accessible. Here were people that I have been following for years, like Chad Fowler, Obie Fernandez, Charles Nutter, and Yehuda Katz, that I got to meet face-to-face, as well as people I hadn’t heard about but are now on my follow list, such as Blythe Dunham, Jim Weirich (have you learned to play Hawaiian Lullabye on your uke yet?), and Desi McAdam, founder of DevChix. I don’t know if it is because everyone was a Rails developer (and following the Rails way), the aloha atmosphere, or what, but it really was a nice crowd of people to hang with.

Last, while there was a lot of good info about how to do Rails right and what is the best stuff to use, the bigger take away for me was how important it is to develop personal connections and get involved in communities. That seemed to be the theme spreading through all the talks…how good things happen when you connect with and share with people outside of your daily job tasks. So that is my new mantra…Get Connected. The first thing I did when I returned to work was to join an online community of tech people on the Big Island, and I have already exchanged emails with a couple of people (whoo hoo, I am not alone). Next, I need to get involved with an open source community. It might be something in the cloud, or some Rails project (maybe a cloud one), I don’t know. If you have suggestions, pass them on.

So, anyway, I am pretty energized by the small conference experience. If you haven’t done one, you gotta try it. And a BIG thanks to Seth for making it happen. Great job.

Rails Generate Window Not Appearing With JDK 6u12

A few people have reported that when they right-click a Rails project node in the NetBeans IDE and choose Generate from the pop-up menu, nothing happens. One user reported that the problem is caused by an interaction with the Java Development Kit (JDK) 6u12. To fix this problem, download a different version of the JDK, such as 6u11, and point the IDE to that installation. See my previous blog for instructions on how to use a different JDK.

Using Gems With JRuby

If you are new to JRuby, you might not know that you cannot use a gem that has native extensions with JRuby, unless that gem builds its library in a platform-neutral manner. When you use the JRuby gem executable to try to add such a gem to your repository, you will get a message like this.

Building native extensions.  This could take a while...
ERROR:  Error installing rmagick:
ERROR: Failed to build gem native extension.
C:/jruby/jruby-1.1.5/bin/jruby.bat extconf.rb install rmagick --no-rdoc --no-ri
C:/jruby/jruby-1.1.5/lib/ruby/1.8/mkmf.rb:7: JRuby does not support native extensions. Check wiki.jruby.org for alternatives. (NotImplementedError)
from C:/jruby/jruby-1.1.5/lib/ruby/1.8/mkmf.rb:1:in `require'
from extconf.rb:1
Gem files will remain installed in C:/rubyrepos/jrubygemrepo/gems/rmagick-2.9.1 for inspection.
Results logged to C:/rubyrepos/jrubygemrepo/gems/rmagick-2.9.1/ext/RMagick/gem_make.out

As you would guess, you then need to hunt for an equivalent gem that will work with JRuby. Anything with “pure Ruby” in its description is a good bet. In the case of RMagick, there is a RMagick4j. Some other examples JRuby compatible gems are
Mongrel, Hpricot, ImageVoodoo, JRuby-OpenSSL, JRuby/LDap, json_pure, and postgres_pr.

If you are developing with both Ruby and JRuby, you might want to create a separate repository that holds the gems that work for both implementations, and then put that repository into your GEM_PATH. That way, you won’t have to install the gem twice. If you are using NetBeans IDE, use the Ruby Platform Manager to add the repository to a platform’s GEM_PATH.

If you want to require a certain gem based on whether you are running on JRuby, you can check whether JRUBY_VERSION is defined.

Telling NetBeans IDE Which JDK to Use

A customer has filed a bug about the Generator menu item not working for NetBeans Rails projects if the IDE is using version 6u12 of the Java Development Kit (JDK) software.

Not knowing how to tell the IDE to use a different JDK, the user reinstalled the NetBeans software.

If you don’t know already, there is no need to go to such lengths. Here are two ways to tell the IDE which JDK to use.

  • Specify the JDK in the startup command. Modify the command that starts the IDE to include the --jdkhome option pointing to the desired JDK. For example:

    netbeans-install-dir/bin/netbeans.exe --jdkhome "%JAVA_HOME%"

    The above example uses the %JAVA_HOME% environment
    variable, which is set to C:\Program Files\Java\jdk1.6.0_10, but you can just supply
    in the path instead. If it has spaces in it, put the path in
    quotes (that’s why the environment variable is in quotes).

  • Specify the desired JDK in the netbeans.conf file. Open the netbeans-install-dir/etc/netbeans.conf file, look for the following option and set it to point to the desired JDK. You might need to unremark the setting.

    netbeans_jdkhome="path-to-jdk"

  • If you are not able to modify the netbeans.conf file because you are sharing the installation or you don’t have permission, you can instead create an etc folder in your NetBeans userdir and put a netbeans.conf file in the etc folder. You only need to put in the options that you want to override. For more information see the
    How do I make my custom startup parameters permanent? FAQ.

Installing Your Own JRuby to Use With the NetBeans IDE

The Ruby support for NetBeans includes a bundled JRuby installation. This is great for quickly getting started with the IDE, but I recommend that you download and install your own version of JRuby and use that one instead. There are a few reasons for doing so, one of which is that the next time you install a NetBeans version, you will get a new bundled JRuby installation,
most likely a different version. If you have added gems to the old bundled JRuby, you will have to reinstall those gems to the new bundled JRuby.

Another reason is when you want to work with more recent JRuby version. For this reason alone, it is good to learn how to install JRuby and register it with the IDE. Below are the steps that I do to add a JRuby installation.

  1. First download JRuby from the JRuby site and
    install it by following the Getting Started instructions.

    TIP: If you are downloading the 6RC1 version, after you unpack it, rename the directory from jruby-1.1.6RC1 to jruby-1.1.6. For some reason, The GlassFish app server barfs on the RC1 in the path name.

  2. Put JRuby’s bin in your environment path. I remember reading some recommendation that if you have both Ruby and JRuby,
    put JRuby after Ruby in the path. Because I switch out JRuby versions often, I created a JRUBY environment variable that
    points to the bin directory of the JRuby that I am working with, and I added the JRUBY environment variable to my path. To test it, I type jruby -v on the command line.

  3. Now you can register your new JRuby installation with the NetBeans IDE. Choose Tools > Ruby Platforms from
    the main menu. Choose Add Platform, and navigate to and select the JRuby executable in the bin directory.
    If you are on Windows, this is jruby.bat. Click Open.

  4. This step is optional, and I don’t suggest it if you are new to Ruby and installing gems. I get tired of having to install the same gems over and over every time I upgrade JRuby, so
    I create a separate repository (outside of the installation folder) for the gems. If you want to do this,
    click the Browse button to the right of the Gem Home text box, type the path to your gem repository,
    and click Open. (If you
    don’t have one yet, use the New Folder button in the dialog box to create it, such as some-ruby-repo-path/jrubygemrepo. When you click Open, it will ask if you want to set up
    your repository there, click OK.)

    Next click the Add button to the right of the Gem Path text box and add the repository to the gem path.

  5. You will need the debugger gems. Follow the instructions on the NetBeans Ruby Debugger wiki page.
    Make sure you get the correct versions — the ones noted on the wiki page. If you opted for a separate gems repository
    in the previous step, then add --install-dir your-repo-path to the gem install
    commands.

  6. Next, I install Rails. You can do this from
    the command line, or from the IDE’s Ruby Gems Manager, which is available from the main menu. When you open the Ruby
    Gems manager, click the Settings tab and select Fetch All Versions so that you
    have a choice of which version to download. Then click the New Gems tab
    and click Reload Gems. Select Rails and click Install. You will be asked
    to select a version.
    If you want to follow the 6.5 tutorials,
    be sure to install Rails 2.1.2 or 2.1.0 because you need Rails 2.1.* for the tutorials. Version 2.1.1 is not compatible with JRuby.

  7. Some other gems you might want to install right away are jruby-openssl, Active Record JDBC Adapter, and the JDBC
    adapters for the databases that you use. See
    Using Database Servers With JRuby
    for more information about the JDBC adapters.

Hopefully, this is complete enough to get you going. Please add comments if you have suggestions or steps to add.

no such file to load — mysql

Rails never fails me. As soon as I publish a series of
tutorials for a NetBeans release, a new Rails release comes
out which breaks my tutorials (and, apparently, most everyone
else’s). Gratefully, some customers
took the time to click the Feedback button at the end
of our tutorials to let us know the tutorials were no longer working.
One customer wrote:


“When trying to create the database following the steps indicated, I got an error indicating
the mysql gem had been removed from Rails 2.2.2 and that I should install the mysql gem.
(Note from me: the actual error message is
“The bundled mysql.rb driver has been removed from Rails 2.2. Please
install the mysql gem and try again: gem install mysql.”)
However, that gem is also native and can’t be installed with JRuby (the misleading
directive to do so from NetBeans was really annoying).”

I have to agree that this is indeed REALLY annoying. However, the “misleading
directive” comes from Rails, and not from NetBeans. And, since Rails 2.2
came out after NetBeans 6.5, this was an unexpected message.

While the directive may be true for Ruby, it is not true
for JRuby, because the the MySQL adapter is included with JRuby.
In addition, as the user pointed out,
you can’t install the mysql gem with JRuby because you cannot use
any gems that build native C libraries during the install process,
and that includes the mysql gem.

I did some googling and found two solutions:

  • Use the activerecord-jdbcmysql-adapter. You can find
    the instructions on how to do that here.
  • Copy the MySQL driver to your project’s lib folder. If you have an older Rails version, you can copy the Ruby MySQL driver
    (mysql.rb) from
    rails-install-dir/gems/activerecord-version/lib/active_record/vendor/mysql.rb
    to the project’s lib directory. Unfortunately, you have to do this for
    every JRuby project.

If anyone else has any other solutions, please post a comment.

P.S. For all you Ruby programmers, when you try out a tutorial, you really should
pay attention to what gem versions the tutorial was written for. Gem releases such
as Rails and RSpec are not always backwards compatible, so there is a chance
that the tutorial will not work
with releases that came out after the tutorial was written.