An Architect's View

CFML, Clojure, Software Design, Frameworks and more...

An Architect's View

Getting Started with FW/1 in Clojure

November 10, 2011 ·

Now that FW/1 is available for Clojure, you might have looked at the examples that are in the FW/1 github repo and wondered how to create your own FW/1 application from scratch.

Assuming you have Leiningen 1.x installed, the easiest way to get started is to install the lein-newnew task and the fw1-template plugin:

> lein plugin install lein-newnew 0.2.7
> lein plugin install fw1-template 0.1.0
Copying 1 file to /tmp/lein-c52739ef-eef2-485c-834c-59b4983fafb2/lib
Including fw1-template-0.1.0.jar
Created fw1-template-0.1.0.jar

For Leiningen 2, you just need to specify the fw1-template as a plugin in your ~/.lein/profile.clj file:

{:user {:plugins {fw1-template "0.1.0"}}}

That's a one-off task (you'll only need to do that when a new version of the plugin appears). Now you can easily create a FW/1 application:

> lein new fw1 fw1-test

Now you can drop into the new project and run it:

> cd fw1-test/
> lein run
[INFO] artifact org.clojure:clojure: checking for updates from clojars
[INFO] artifact org.clojure:clojure: checking for updates from central
[INFO] artifact org.clojure:clojure: checking for updates from clojure
[INFO] artifact org.clojure:clojure: checking for updates from clojure-snapshots
Copying 21 files to /home/sean/clojure/fw1-test/lib
2011-11-10 09:28:46.557:INFO::Logging to STDERR via org.mortbay.log.StdErrLog
2011-11-10 09:28:46.565:INFO::jetty-6.1.25
2011-11-10 09:28:46.679:INFO::Started  SocketConnector@

Now browse to http://localhost:8080 and see your new FW/1 app running!

NOTE: This assumes you have nothing running on port 8080. If you need to use a different port, you can specify it on lein run like this:

> PORT=8123 lein run

After you edit your Clojure code, just append ?reload=secret to the URL to pick up the changes. If you edit main.clj to change the app configuration (in the (fw1/start) call), you'll need to quit the process (control-C) and restart it (lein run).

Tags: clojure · fw1

0 responses