27

I'm using Leiningen (for the first time) to manage an app my writing. So far I've defined the project dependencies, installed the deps in the project lib directory, and I've defined a function. When I run lein repl from the project root and then call the function I've defined, I get the error unable to resolve symbol. Anyone know what I'm doing wrong and how to correctly run my app via Leiningen? Thanks.

David
  • 81
  • 1
  • 6
sjac
  • 2,811
  • 5
  • 23
  • 20

2 Answers2

30

from the leiningen repl you will have to switch to the namespace your function was defined in with the in-ns macro.

(in-ns 'myproject.core)

then the function should be available
you could also use that namespace from the repl to include it in the default (user) namespace.

(use 'myproject.core)

after that you may want to consider looking into the lein run, lein uberjar, and lein jar leiningen tasks.

Arthur Ulfeldt
  • 90,827
  • 27
  • 201
  • 284
  • I wasn't aware of `lein run`, can you point me to where I can find mroe information? I've set `:main` to my project namespace, but I'm having a bit of difficulty using `lein run` with arguments; I'm continually getting `Exception in thread "main" java.lang.NullPointerException (NO_SOURCE_FILE:1)` – sjac Jul 22 '11 at 23:49
  • 1
    If you execute `lein help` (or even just `lein` on its own) a list of commands is displayed. You can dig deeper with the name of the command; for example: `lein help run` – Scott Jul 23 '11 at 09:12
16

In my projects, for a core.clj file which contains a namespace defined thus:

(ns my-project.core)

... I set the :main key in Leiningen's defproject map in project.clj:

(defproject my-project "1.0.0-SNAPSHOT"
  :description "My project description"
  :dependencies [[org.clojure/clojure "1.2.1"]]
  :main my-project.core)

So when I run lein repl, my core namespace is automatically loaded, and I see this:

mac:my-project scott$ lein repl
REPL started; server listening on localhost:31515.
my-project.core=> 
Scott
  • 17,127
  • 5
  • 53
  • 64
  • 1
    If I were to use `:main`, does hot-code depolyment take place automatically? – sjac Jul 22 '11 at 23:10
  • 7
    I'm not sure if you are asking if the Leiningen automatically looks for file changes and loads them into your live REPL, but it doesn't do that. However, rather than restart the REPL you can execute the following to load the latest code: `(use :reload-all 'my-project.core)` – Scott Jul 23 '11 at 09:07