Yesterday I started using leiningen and saw that it can run my
programs. So I converted my project layout so that leinigen can use
that.
My project is currently quite simple. The program needs a single
argument, filename, to read from. So I added a :main entry into
project.clj and started
$ lein run
this took some time and crashed with an exception, because I did not
specify a file. Well, that was to be expected. So I thought I just add
an argument:
$ lein run filename
Instead of the output, I got this stacktrace:
Exception in thread "main" java.lang.Exception: Unable to resolve
symbol: filename in this context (NO_SOURCE_FILE:1)
at clojure.lang.Compiler.analyze(Compiler.java:5205)
at clojure.lang.Compiler.analyze(Compiler.java:5151)
at clojure.lang.Compiler$InvokeExpr.parse(Compiler.java:3057)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:5371)
at clojure.lang.Compiler.analyze(Compiler.java:5190)
at clojure.lang.Compiler.analyze(Compiler.java:5151)
at clojure.lang.Compiler$BodyExpr$Parser.parse(Compiler.java:4670)
at clojure.lang.Compiler$FnMethod.parse(Compiler.java:4328)
at clojure.lang.Compiler$FnExpr.parse(Compiler.java:3173)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:5367)
at clojure.lang.Compiler.analyze(Compiler.java:5190)
at clojure.lang.Compiler.eval(Compiler.java:5421)
at clojure.lang.Compiler.eval(Compiler.java:5415)
at clojure.lang.Compiler.eval(Compiler.java:5391)
at clojure.core$eval.invoke(core.clj:2382)
at clojure.main$eval_opt.invoke(main.clj:235)
at clojure.main$initialize.invoke(main.clj:254)
at clojure.main$null_opt.invoke(main.clj:279)
at clojure.main$main.doInvoke(main.clj:354)
at clojure.lang.RestFn.invoke(RestFn.java:422)
at clojure.lang.Var.invoke(Var.java:369)
at clojure.lang.AFn.applyToHelper(AFn.java:165)
at clojure.lang.Var.applyTo(Var.java:482)
at clojure.main.main(main.java:37)
Caused by: java.lang.Exception: Unable to resolve symbol: filename in
this context
at clojure.lang.Compiler.resolveIn(Compiler.java:5677)
at clojure.lang.Compiler.resolve(Compiler.java:5621)
at clojure.lang.Compiler.analyzeSymbol(Compiler.java:5584)
at clojure.lang.Compiler.analyze(Compiler.java:5172)
... 23 more
Any ideas what I'm doing wrong? It seems to try to evaluate the
arguments as symbols, but for what purpose? I need a string...
regards,
Marek
> My project is currently quite simple. The program needs a single
> argument, filename, to read from. So I added a :main entry into
> project.clj and started
>
> $ lein run
>
> this took some time and crashed with an exception, because I did not
> specify a file. Well, that was to be expected. So I thought I just add
> an argument:
>
> $ lein run filename
>
> Instead of the output, I got this stacktrace:
>
> Exception in thread "main" java.lang.Exception: Unable to resolve
> symbol: filename in this context (NO_SOURCE_FILE:1)
I think this is a bug. I've sent Phil a pull request with a proposed
fix:
http://github.com/ato/leiningen/commit/3f299cc560dbf7101c44a08d98da4177d6f326cc
In the meantime you should be able to work around it by using:
$ lein run -m your.namespace filename
Or alternatively quoting the first argument like this:
$ lein run '"filename"'
> I think this is a bug. I've sent Phil a pull request with a proposed
> fix:
>
> http://github.com/ato/leiningen/commit/3f299cc560dbf7101c44a08d98da4177d6f326cc
Yep, bendlas in #clojure helped me to diagnose. Great that you have a
fix already, thanks!
> In the meantime you should be able to work around it by using:
>
> $ lein run -m your.namespace filename
Yes, that works.
> Or alternatively quoting the first argument like this:
>
> $ lein run '"filename"'
Good to know, that looks a bit "nicer" than repeating what is defined
in project.clj already.
Thanks a lot, hope the bugfix will get pulled soon :)
regards,
Marek