I had used some library, let's say it is Clojure itself (which is always added to project.clj
). Clojure provides clj
CLI tool (which is src/cli/clojure/main.clj
, but nevermind). How to use it with lein
? I mean, is there any command/plugin/technique which will allow me to use library's main
?
Asked
Active
Viewed 171 times
1

Anthony
- 1,877
- 17
- 21
1 Answers
1
Every Var
in every namespace is equal in the eyes of Clojure. From your code, just execute like:
(some.awesome.lib/-main ...)
or whatever the fully-qualified symbol pointing to the Var
in question.
For further details, please see this question:
Also
See the output of
> lein help run
Using lein, you can type
lein run -m my.awesome.proj/some-fn
or
lein run -m some.awesome.lib/-main
since to Clojure some.awesome.lib/-main
is no different than any other function (the hyphen prefix on -main
is just a convention and makes no difference to the Clojure compiler).
You can also set up project.clj
to automatically call any function of your choosing when you type lein run
by adding:
:main some.awesome.lib/-main

Alan Thompson
- 29,276
- 6
- 41
- 48
-
I don't want to execute it in my code, but I do want to execute it with `lein` tool. – Anthony Sep 08 '21 at 05:52
-
Thank you. I don't know *how* I read help for `run` sub-command, but I didn't see the `-m` option. This is what exactly I wanted. – Anthony Sep 08 '21 at 06:09
-
1`lein run some.awesome.lib` should work for `-main` in `some.awesome.lib`? – cfrick Sep 08 '21 at 06:21
-
Yeah, there's no "in your project" vs "not in your project" distinction. You can confirm this without even needing a dependency: `lein run -m clojure.main` works fine, and clojure.main certainly isn't in my project. – amalloy Sep 08 '21 at 07:55
-
Ya know, I tested that and must have made a mistake! Fixed. – Alan Thompson Sep 08 '21 at 13:58