Thursday Feb 19, 2009
Thursday Feb 19, 2009
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.
Wednesday Feb 18, 2009
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.
Thursday Feb 12, 2009
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.
Monday Feb 09, 2009
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.
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.
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.
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.
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.
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.
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.
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.
Tuesday Feb 03, 2009
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:
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.