Beyond The Type

Tweetobix

November 22nd 2008

Published as a follow up to my talk given at RubyManor in November 2008.

A JRuby Twitter client built using MonkeyBars. As demo’d at RubyManor!

Tweetobix login

Before you start

Create the App skeleton

  $. monkeybars projectname
  $. cd projectname
  $. rawr install
  # (choose option 2)
  $. jruby -S rake generate ALL=‘src/login’

Install Gems & Unpack Gems

  $. jruby -S gem install twitter
  $. cd lib/ruby
  $. jruby -S gem unpack twitter
  $. jruby -S gem unpack hpricot

Enter NetBeans

  1. File > New Project. Choose Java category > Java Project with existing sources
  2. Give your app a name and set project folder to where you created your app [hit next]
  3. Exsisting sources – choose the src directory in your app [hit finish]

Your project will now appear in NetBeans. There are a couple more things to do before you can begin.

  1. In a terminal (not NetBeans) copy jruby-complete.jar into the lib/java directory.
  2. Back in NetBeans.. right click the Libraries folder. Choose ‘Add Jar/Folder’ and choose jruby-complete.jar you just added.
  3. Again right click on the Libraries folder and choose ‘Add Library…’ and select ‘Swing Layout Extensions’

Next we setup a frame to display the GUI for the login:

  1. Right click on login directory. Choose ‘New > New Frame Form’.
  2. Name it ‘LoginFrame’ (it can be anything you like but probably best sticking with NameFrame convention)
  3. You can now start building your interface. woot!

Remember to update your login_view.rb with the name of the frame. e.g.

class LoginView < ApplicationView
  set_java_class ‘login.LoginFrame

Running the project

Still in NetBeans.. Hit the run (play icon) button. It will ask which class you want to choose for the ‘main class’. Choose ‘org.rubyforge.rawr.Main’.

Note, if things don’t go to plan you can still set this by right clicking on the project name and choosing from the menu ‘Set Configuration > Customize…’. The main class can be set in the ‘Run’ section of the configuration dialog that pops up.

Packaging for distribution

rake rawr:bundle:app    # Bundles the jar from rawr:jar into a native Mac OS X application (.app)
rake rawr:bundle:exe    # Bundles the jar from rawr:jar into a native Windows application (.exe)
rake rawr:bundle:web    # Bundles the jar from rawr:jar into a Java Web Start application (.jnlp)

Gotchas

  • Embedding images in Netbeans kills the rawr build (null.pointer.exception) – there is a workaround for this in rawr 1.0
  • Some Ruby gems won’t run on JRuby e.g. Twitter4R
  • Hpricot doesn’t compile using the latest version of RAWR
  • Monkeybars doesn’t seem to require frozen gems automatically from lib/ruby
  • Make sure you have jruby-complete.jar and swing-layout-1.0.3.jar in you lib/java directory
  • Both those jars need to be added to the manifest for packaging.
  • Sometimes build paths get set incorrectly, and it can be difficult to find out why..
  • Have to remove all mention of “require ‘rubygems’” from frozen gems to make packaging work?!

Sample Application – Download and Source code

Coming Soon!

  1. Download for Mac (app)
  2. Download for Windows (.exe)
  3. Download for Linux and all other platforms (jar)

Source Code:


 git clone git://github.com/martinbtt/tweetobix.git

Or go direct to the Tweetobix project page on github

Useful Resources

Notes

At the time of writing there are a few aspects of the packaging process that are not working. (See gotchas…) Hopefully with a bit of further investigation and feedback we can get it working. I will keep updating this page as things progress.

Screenshots

Tweetobix main page

Tweetobix friends timeline page and tweet box.

Recommend Me

blog comments powered by Disqus