Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 105 lines (68 sloc) 2.88 kb
04c9f55 Added depracation message to the README.
Siddhartha Reddy authored
1 DEPRECATED
2 ==========
3
4 This plugin is now deprecated in favor of the built-in run task in Leiningen
5 1.4 and later. The built-in run task is a subset of the lein-run plugin with
6 some undesired functionality removed.
7
7eb02d5 Updated the README with an example.
Siddhartha Reddy authored
8 lein-run Leiningen Plugin
9 =========================
10
e74058f Initial commit.
Siddhartha Reddy authored
11 A leiningen plugin to call a function in a new process or run a .clj file.
12
13 lein-run is extremely useful when you want to launch long-running
14 Clojure process from the command line. For example, it can be used to
15 start a server (a web server like Compojure) or to start a process
ae909a4 Updated README.
Siddhartha Reddy authored
16 that will run in an infinite loop (a process waiting for messages from
17 a message queue, a twitter client etc.)
e74058f Initial commit.
Siddhartha Reddy authored
18
7eb02d5 Updated the README with an example.
Siddhartha Reddy authored
19 Setup
20 -----
e74058f Initial commit.
Siddhartha Reddy authored
21
22 lein-run is available from [clojars](http://clojars.org/lein-run).
23 Just add it as a dependency in your project.clj and you're good to
24 go. Refer the [clojars page](http://clojars.org/lein-run) for the
25 latest version to use.
26
73042ba Release 1.0.0!
Siddhartha Reddy authored
27 :dev-dependencies [[lein-run "1.0.0"]]
7eb02d5 Updated the README with an example.
Siddhartha Reddy authored
28
29 Usage
30 -----
e74058f Initial commit.
Siddhartha Reddy authored
31
32 lein run <file> [<arg> ...]
33
7eb02d5 Updated the README with an example.
Siddhartha Reddy authored
34 file must be a path relative to the project root. It will be run
73042ba Release 1.0.0!
Siddhartha Reddy authored
35 using clojure.main/main. Args will be passed on as `*command-line-args*`.
e74058f Initial commit.
Siddhartha Reddy authored
36
37 lein run <namespace> [<function> [<arg> ...]]
38
7eb02d5 Updated the README with an example.
Siddhartha Reddy authored
39 If function is not given, it defaults to -main. Calls
e74058f Initial commit.
Siddhartha Reddy authored
40 namespace/function passing it all the args.
41
42 lein run <alias> [<arg> ...]
43
44 Aliases for running a file or calling a function can be defined in
45 project.clj and referred to here. Args from the command line are
46 appended to args from the alias definition.
47
48 :run-aliases {:alias1 [a-namespace a-function "arg1" "arg2"]
49 :alias2 ["a-file" "arg1" "arg2"]}
50
ae909a4 Updated README.
Siddhartha Reddy authored
51 Alias names can be keywords or strings. All args will be converted to
52 strings.
e74058f Initial commit.
Siddhartha Reddy authored
53
7eb02d5 Updated the README with an example.
Siddhartha Reddy authored
54 Example
55 -------
56
57 Let's say you have a simple Compojure webapp:
58
59 (ns hello-www.core
60 (:use compojure.core
61 ring.adapter.jetty)
62 (:require [compojure.route :as route]))
63
64 (defroutes example
65 (GET "/" [] "<h1>Hello World Wide Web!</h1>")
66 (route/not-found "Page not found"))
67
68 (defn start-server [port]
ae909a4 Updated README.
Siddhartha Reddy authored
69 (run-jetty example {:port port}))
70
71 (defn -main [& [port]]
72 (if port
73 (start-server (Integer/parseInt port))
74 (start-server 8080)))
7eb02d5 Updated the README with an example.
Siddhartha Reddy authored
75
76 You can start the server this way:
77
78 lein run hello-www.core start-server 8080
79
80 You can also define an alias:
81
ae909a4 Updated README.
Siddhartha Reddy authored
82 :run-aliases {:server [hello-www.core -main]}
7eb02d5 Updated the README with an example.
Siddhartha Reddy authored
83
84 and then use it to start the server:
85
86 lein run server 8080
87
88 If you hardcode the port into the alias definition:
89
ae909a4 Updated README.
Siddhartha Reddy authored
90 :run-aliases {:server [hello-www.core -main 8080]}
7eb02d5 Updated the README with an example.
Siddhartha Reddy authored
91
92 you won't have to specify it on the command line:
93
94 lein run server
95
96 License
97 -------
e74058f Initial commit.
Siddhartha Reddy authored
98
99 Copyright (C) [Siddhartha Reddy](http://www.siddhartha-reddy.com/).
100
101 Thanks to Phil Hagelberg, Alex Osborne and Dan Larkin for the terrific
102 build tool that is leiningen.
103
104 Distributed under the Eclipse Public License, the same as Clojure uses. See the file COPYING.
Something went wrong with that request. Please try again.