Over the course of this book, we're going to use a number of third-party libraries and external dependencies. We need a tool to download them and track them. We also need a tool to set up the environment and start a read-eval-print-loop ( REPL, or interactive interpreter), which can access our code, or to execute our program.
We'll use Leiningen for that (http://leiningen.org/). This has become a standard package automation and management system.
Visit the Leiningen site (http://leiningen.org/) and download the lein
script. This will download the Leiningen JAR file. The instructions are clear, and it's a simple process.
To generate a new project, use the
lein new
command, passing it the name of the project:
$ lein new getting-data Generating a project called getting-data based on the 'default' template. To see other templates (app, lein plugin, etc), try 'lein help new'.
Now, there will be a new subdirectory named getting-data
. It will contain files with stubs for the
getting-data.core
namespace and for tests.
Tip
Downloading the example code
You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.
The new project directory also contains a file named project.clj
. This file contains metadata about the project: its name, version, and license. It also contains a list of dependencies that our code will use. The specifications it uses allows it to search Maven repositories and directories of Clojure libraries (Clojars, https://clojars.org/) to download the project's dependencies.
(defproject getting-data "0.1.0-SNAPSHOT" :description "FIXME: write description" :url "http://example.com/FIXME" :license {:name "Eclipse Public License" :url "http://www.eclipse.org/legal/epl-v10.html"} :dependencies [[org.clojure/clojure "1.4.0"]])
In the Getting ready section of each recipe, we'll see what libraries we need to list in the :dependencies
section of this file.