本文内容来自:https://github.com/technomancy/leiningen/blob/preview/doc/TUTORIAL.md
不过只描述最简单的部分,不会冗长而让人知难而退。
运行下面的命令,就可创建第一个工程
$ lein new project1 Generating a project called project1 based on the 'default' template. To see other templates (app, lein plugin, etc), try `lein help new`.
可以看出这里使用了default模板创建了工程。project1目录被创建,目录结构如下:
tree . └── project1 ├── CHANGELOG.md ├── doc │ └── intro.md ├── LICENSE ├── project.clj ├── README.md ├── resources ├── src │ └── project1 │ └── core.clj └── test └── project1 └── core_test.clj 7 directories, 7 filesproject.clj是项目文件,打开后看一下:
(defproject project1 "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.7.0"]])
;; Dependencies are listed as [group-id/name version]. :dependencies [[org.clojure/clojure "1.3.0"] [org.jclouds/jclouds "1.0" :classifier "jdk15" :scope "test"] [net.sf.ehcache/ehcache "2.3.1" :extension "pom"] [log4j "1.2.15" :exclusions [[javax.mail/mail :extension "jar"] [javax.jms/jms :classifier "*"] com.sun.jdmk/jmxtools com.sun.jmx/jmxri]]]/ 斜线前面的是group id,后面的是artifact id,然后是版本号。熟悉Maven的Java程序员一看就会。用[ ] 将依赖之间分开。
测试代码在test子目录,程序代码在src子目录。看一下程序代码core.clj:
(ns project1.core) (defn foo "I don't do a whole lot." [x] (println x "Hello, World!"))
(defn foo ...) 是定义了一个函数, 就是打印了一个Hello, World字符串。