Jeff Devine dot Com

The Cloud Computing Consultant

In Tech on October 11, 2009 at 3:46 pm

Hilar­i­ous video about the state of cloud com­put­ing. It’s cer­tainly a lit­tle inside base­ball, but if you fol­low this stuff, you’ll love it.

Simple-Build-Tool or: How I RTFM and stopped hating on Maven

In Tech on September 27, 2009 at 2:51 am

Tonight I was sup­posed to see WHY? at Le Pois­son Rouge but for some com­pletely unknown rea­son, I felt I would be bet­ter served stay­ing in and working.

I’m try­ing to pro­to­type a Scala-based REST API that gets called by a GWT front-end. My Scala is extremely weak but Mar­tin Kleppmann’s Yes/No/Cancel had a great write-up accom­plish­ing the afore­men­tioned task using Jer­sey and Scala. Unfor­tu­nately for me, I’ve man­gled my java envi­ron­ment try­ing to get GWT to run on Snow Leop­ard and I was hav­ing no luck get­ting Martin’s Maven POM to work.

Already regret­ting my deci­sion to pass on the con­cert, I wasn’t going to waste my entire night curs­ing at Maven. Instead I took this oppor­tu­nity to use Martin’s exam­ples but apply them to Sim­ple Build Tool. The fol­low­ing is how I RTFM and started learned how to use SBT. I’d love feed­back so please look it over or fol­low along and let me know if there is a bet­ter way to go about this.

First, start a new project by cre­at­ing a direc­tory for the project and run­ning sbt from within this new direc­tory. When SBT is run with no action spec­i­fied and it doesn’t detect a project struc­ture, it prompts to cre­ate a new project. I used the fol­low­ing, mostly tak­ing the default values:

     Name: api
     Organization []: com.jeffdevine
     Version [1.0]:
     Scala version [2.7.5]:
     sbt version [0.5.3]:

The ini­tial process down­loads any depen­den­cies needed and cre­ates a default project structure:

    lib/
    project/
          boot/
          build.properties
    src/
          main
              resources/
              scala/
          test
              resources/
              scala/
    target/

My ini­tial needs for pro­to­typ­ing the REST API are Jetty and Jer­sey, so I con­fig­ured SBT to man­age these depen­den­cies by adding the file ./project/build/ApiProject.scala (note: build is a new directory):

import sbt._
 
class ApiProject(info: ProjectInfo) extends DefaultWebProject(info)
{
   val snapshots = "Java.net Repository" at "http://download.java.net/maven/2/"
   val jetty6 = "org.mortbay.jetty" % "jetty" % "6.1.14" % "test->default"	
   val jersey = "com.sun.jersey" % "jersey-server" % "1.1.2-ea" % "test->default" 
   val jsr311 = "javax.ws.rs" % "jsr311-api" % "1.1-ea" % "compile->default"
}

From the SBT inter­ac­tive ses­sion, exe­cute reload to recom­pile the project def­i­n­i­tion and update to down­load all the spec­i­fied dependencies.

Back to Martin’s exam­ple, I slightly mod­i­fied his Scala code and saved it in ./src/main/scala/Hello.scala:

package com.jeffdevine.api
import javax.ws.rs._
 
@Path("/hello")
class Hello {
  @GET @Produces(Array("text/html"))
  def doGet = "<html><body><p>Hello? You could be seeing Why? right now...</p></body></html>"
}

The last bit is to tell Jetty what to do by cre­at­ing a file in ./src/main/webapp/WEB-INF/web.xml (note: you’ll need to cre­ate the direc­tory struc­ture webapp/WEB-INF):

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
  <servlet>
    <servlet-name>Example REST API</servlet-name>
    <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
    <init-param>
      <param-name>com.sun.jersey.config.property.packages</param-name>
      <param-value>com.jeffdevine.api</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>Example REST API</servlet-name>
    <url-pattern>/*</url-pattern>
  </servlet-mapping>
  <session-config>
    <session-timeout>30</session-timeout>
  </session-config>
</web-app>

Back in SBT, exe­cute jetty-run, and within a few sec­onds, jetty is serv­ing the API on http://localhost:8080/hello. Fir­ing off a GET request returns the HTML

     Hello? You could be seeing Why? right now...

Exe­cut­ing jetty-stop will kill the server, and jetty-restart restarts jetty, pick­ing up any code changes.

While this is a basic exam­ple that could use a test case or two, it has given me what I need to start pro­to­typ­ing and I no longer feel like a schmuck for skip­ping tonight’s con­cert… which would have gone some­thing like this:

Happy HP Mac Mini

In Tech on September 21, 2009 at 11:21 pm

I’ve had an HP Mini 1000 net­book for the last few months run­ning a man­gled and out­dated copy of iDeneb with lack­lus­ter results. Per­for­mance was fine but you could tell some­thing wasn’t right which I attrib­uted to run­ning old code and hacked kexts.

Sun­day night I hap­pened across the excel­lent blog Mac­book Mini only to find a freshly baked step-by-step guide to installing Snow Leop­ard straight from the Retail DVD… bar­ring the fact that the HP has no DVD drive.

The steps where clear and con­cise and under a few hours with no major pain or bruis­ing, my Mini HP is run­ning like a champ. The only draw­back is sleep doesn’t work, but I’ll take the abil­ity to backup Time Machine over-the-air any day.

Inter­net mir­a­cles really do hap­pen everyday.