You can always make more money later, but you can't make more time.
- Randy Pausch
Monday, April 30, 2012
Friday, April 20, 2012
To see a world in a grain of sand and a heaven in a wild flower, hold infinity in the palm of your hand and eternity in an hour. -- William Blake
Wednesday, April 04, 2012
Quick-start with Lift, Scala, and mongodb on Mac OS X
Earlier, I wrote about the programming language, Scala. I had planned to follow with a similar, somewhat academic discussion of the Lift Web Framework, which is based on Scala, and mongodb, a NoSQL database, before going into practical stuff like how to get started with this stack. But I can't help it but get my hands dirty, so here's how to get started. I'll go back and explain why I chose these components later!
First, the development environment. In my opinion, Mac OS X provides the most capable and powerful software development environments for all platforms that I've encountered, unless you're developing in .NET. I started programming at a Unix shell prompt, and call me old-fashioned, but try as I have, I'm just not feeling the love for IDEs. I'll leave that part of the environment setup for someone else to cover.
One missing piece of the OS X platform is a capable package manager. I chose Homebrew (http://mxcl.github.com/homebrew/). Installation is simple:
bash$ /usr/bin/ruby -e "$(/usr/bin/curl -fksSL https://raw.github.com/mxcl/homebrew/master/Library/Contributions/install_homebrew.rb)"Just follow the prompts. Then update so that the following installations are current:
bash$ brew updateNext, you'll need a build manager for your Scala projects. I chose SBT (Simple Build Tool - https://github.com/harrah/xsbt/wiki). SBT requires Java 1.6 or later, but I'll assume that you already have a suitable Java environment on your Mac.
bash$ brew install sbtMaven is another popular choice that might be more familiar to you if you're a Java developer.
Install mongodb (http://www.mongodb.org/display/DOCS/Quickstart+OS+X)
bash$ brew install mongodbInstall giter8 (https://github.com/n8han/giter8#readme). Wait a minute: Scala, Lift, and mongodb. You didn't mention giter8! What is it? It's a tool that lets you generate a local source tree from templates on Github. I'll use this later to generate source tree for a Lift, Scala, and mongodb app from a very nice template.
bash$ g8 eltimn/lift-mongo bash$ cd [your-project-name]Here, in your project directory, you'll find a README.md file that will walk you through configuring your new project. Here's a summary for convenience. Twitter Bootstrap is included via a git submodule, so after generating your source tree, you'll need to go to the project root directory and do the following:
bash$ git init bash$ git submodule add https://github.com/twitter/bootstrap.git modules/bootstrap bash$ git submodule init bash$ git add modules/bootstrap bash$ cd modules/bootstrap bash$ git co v1.4.0This will pull in the necessary files. Note that this template is built against Bootstrap 1.4. The current version is Bootstrap 2. I'm hoping that I won't have to upgrade anytime soon!
Next, configure mongodb. I installed mongodb locally for my development environment. If you do the same, you won't have to configure your application for mongodb; the Lift defaults will work just fine.
IMPORTANT: Due to a Mac OS/Java driver bug in which localhost:27017 is translated to <public-machine-name>/<public-ip-address>:27012, you will need to change the default mongodb setting and allow connections from everywhere (or at least from your local machine's public IP address) by commenting out the bind_ip line in /usr/local/Cellar/mongodb/2.0.2-x86_64/mongod.conf. Make sure you understand the security ramifications of doing this.
Then, start mongodb:
bash$ sudo mongod -f /usr/local/Cellar/mongodb/2.0.2-x86_64/mongod.confFinally, build and run the template app:
bash$ sbt > ~;container:start; container:reload /It will take a few minutes to build for the first time, because SBT will download and compile all of the dependencies. Subsequent builds are much faster. The app will start, and any time you change a source file, it will compile and reload automatically. It will be running on http://localhost:8080. Try registering and logging in.
So what did you not have to do in setting up this stack?
- Install an IDE, plug-ins, and lots of libraries
- Do a lot of database or other configuration
- Define or create a database schema
- Install Scala (Really? I'm not 100% sure, but I think SBT took care of this)
- Install Lift and Bootstrap (giter8 took care of this)
- Write any code (yet)
Pretty easy, right? I hope your experience is the same, and I really hope that I didn't forget any steps. Please give this a try and let me know how it goes.
Subscribe to: Posts (Atom)