Archive for the 'OS X' Category

Advanced Spring by Rod Johnson

Wednesday, August 8th, 2007

The Spring man himself, Rod Johnson, gave this talk. He looks better in person than he does on this book cover.

O’Reilly-mandated audience poll:
Using Spring: 90%
Strong knowledge: 50%
Written a BeanPostProcesser: Me + someone else (not that I remember what it was for)
33% of the audience use Spring for data access.
Use Spring version 2: 40%
Use Spring version 1: 10%

Rod says: Spring is easy to customize because of its component model.

What is Spring? Well, it’s a Java framework that makes it easier to work with J2EE, and offers alternatives to the weak spots or omissions in J2EE. That’s my description. Since this was an “advanced” talk, the presenter offered:
Core components with Inversion of Control (IoC), but IoC is really just an enabler.
The triad:

  1. Consistent patterns
  2. Integration
  3. Portable (decouples your business logic from infrastructure)

Gives you: Universal POJO programming model

Spring uses good APIs abstractions like DataSource, and replace bad ones like JTA. and Spring uses configuration meta-data to wire together POJOs.

Rod shows us an example of using AOP pointcut using matching rule. Man, I don’t know. Pointcuts makes sense when I really stare at them, but they are nasty looking.

With Spring and AOP, you can add remoting to any POJO without forcing the POJO to know about it. Likewise, you are not forced to make all service classes remote. Nasty magic AOP and XML config aside, this really is pretty cool. A big practical advantage when you are working with code or writing tests.

Now we talk about FactoryBeans. Rod asks: “who can tell me what a Spring FactoryBean does?” Weak audience response. Uh oh, Rod can tell that we’re not really advanced Spring users. Contempt. (A FactoryBean creates other beans.)

Back to our feature tour programming. You can add the JMX API to you Spring beans. “Very cool.” Of course, only 5% of the audience use JMX.

Spring can use weave any bean with aspects. Example: can audit calls to particular method. Yikes, another pointcut example. I still find the syntax confusing as hell. But, the EJB interception model “sucks” because it’s not typesafe.

We start to pick up to whirlwind tour pace. Rod is cramming his 90-minute JavaOne presentation into 45 minutes.

There are (will be?) new extension points:

  • New XML tags to produce zero or note Spring bean definitions
  • Properties
  • Tags for transactions

What’s coming in Spring 2.1;

  • increased use of annotations for config. and can mix XML and annotations
  • JCA 1.5
  • Improved JPA support
  • Aims: Make Spring still easier to use

Ruby, Rails, and FXRuby on OS X Tiger

Thursday, January 12th, 2006

I needed to install Rails and FXRuby on a couple of my Mac OS X boxes. They are all running Tiger (10.3). I used the Apple development tools that come on the install CD. (I did try the latest dev tools from Apple’s site. I had some problems — probably solvable problems — but the older dev tools were just fine for me, so I rolled back.)

Before you dive into this, ask: do I really want to do this all “by hand?” There are alternatives that install and configure Rails and other Unix software for you. Consider the excellent Locomotive package. DarwinPorts is another good option, although the Fox Ruby packages were an older version (1.2) last time I checked. Finally, there is Fink. Fink is similar to DarwinPorts, although there doesn’t seem to be as much RUby interest there.

Ezra Zygmuntowicz has the best instructions for Rails on OS X that I’ve found. Building Ruby, Rails, LightTPD, and MySQL on Tiger is also helpful. Rather than repeat these instructions, I just added some notes from my experience.

Ruby

OS X comes with ruby installed in /usr/bin. This version doesn’t work so well with the Ruby MySQL bindings and readline. It’s easy to replace with a new copy straight from the source.

You want to make sure OS X will use your version of Ruby. And unless you want to muck around with add “–prefix=” to everything you compile, add a couple lines to your PATH in your ~/.bash_login file:
export PATH="/usr/local/bin:/usr/local/sbin:$PATH"

At least for me, curl needed the ‘–location-trusted option’ to download files from Ruby Forge:
curl --location-trusted -O http://rubyforge.org/frs/download.php/2338/ruby-1.8.2.tar.gz

The SSL patch to Ruby 1.8.2 gave me the following compilation error, so I didn’t use it:
ossl_x509store.c:541: error: 'struct x509_store_ctx_st' has no member named 'param'

It’s entirely possible this patch is very important, but I’m not doing anything with Ruby and SSL right now.

Without the SSL patch, there was a new error:
readline.c:780: error: 'rl_event_hook' undeclared (first use in this function)

So I installed a new (GNU!) version of readline:
curl -v -O http://ftp.gnu.org/pub/gnu/readline/readline-5.1.tar.gz
tar zxvf readline-5.1.tar.gz

GNU readline built and installed without any problems, and then Ruby built fine as well.

MySQL

Like many many other people, I had some problems building the Ruby MySQL bindings. The following worked for me.

Download MySQL 4.1

Add “/usr/local/mysql/bin” to your PATH in .bash_login.

Download MySQL bindings directly, not as a gem

ruby extconf.rb --with-mysql-config

Fox

Sure you don’t want to use DarwinPorts? OK.

Fox requires several image libraries you probably don’t have installed already. I grabbed the versions from the Fox download page and they build and installed with minor tweaks.

The TIFF lib needs a newer version of config files and LZW:
cd tiff-v3.5.7/
cp /usr/share/libtool/config.guess .
cp /usr/share/libtool/config.sub .
cp libtiff-lzw-compression-kit-1.3/tif_lzw.c tiff-v3.5.7/libtiff/

Fox itself:
./configure --enable-shared --enable-static --prefix=/usr --with-opengl=no --x-includes=/usr/X11R6/include

Test from the Terminal:adie

FXRuby

There’s a gem, but I used the source instead.
ruby install.rb config -- --with-fox-include=/usr/include/fox14 --with-fox-lib=/usr/lib/fox14
ruby install.rb setup
sudo ruby install.rb install
irb
require 'fox14'

As a side note, I later enabled font anti-aliasing with XFT using “–with-xft” when I built Fox. But I needed to install several dependencies via DarwinPorts before I could get it to work

gears