每当我启动项目时,都会发生错误:project.clj中指定的主名称空间
无论我运行哪个github项目,我都会收到相同的错误。
现在,我已经从《勇敢和真实》的《 Clojure》一书中启动了一个简单的示例,并且出现了同一程序。
(ns clojure-noob.core
(:gen-class))
(defn -main
"I don't do a whole lot ... yet."
[& args]
(println "I'm a little teapot!"))
错误是
> PS C:\Users\danny\New folder\cftbat-code> lein run
No :main namespace specified in project.clj.
我能做什么,我在做什么错?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是令人惊讶的!显然,键入
lein new myproj
在结果中不包含必要的行。特别是,您的project.clj
文件需要这样的行:将其更改为如下:
以及
结果
另一种选择
,我从不使用
lein new new XXX
了。取而代之的是,我只是克隆此模板项目,然后修改它。只需查看读书我并跟随!
额外的详细信息
您还可以指定在命令行上运行的“主函数”。由于默认“ main函数”的名称为
-main
,您可以通过键入:Lein Run Run
包含-main
函数的命名空间:如果您的“主函数”不是
-main
,则输入类似于汇编失败(尤其是涉及宏)时的内容,删除所有以前的所有
*。类文件通过
Lein Clean
。如果您不这样做,也许一百次,您将获得无法解释的非常奇怪的失败。我发现定义并始终使用别名最安全:
do
的版本比lein Clean快1秒; Lein运行
,但不要忘记逗号!如何避免
确定,我只记得一种避免问题的方法。 JUST类型:
行。
这将包括当您仅键入
lein新myproj
(即带有app app
part)时所缺少的This is surprising! Apparently typing
lein new myproj
does not include a necessary line in the result. In particular, yourproject.clj
file needs a line like this:Change it to look like the following:
and
with result
Another option
Having said that, I never use
lein new xxx
anymore. Instead, I just clone this template project, then modify it.Just check out the README and follow along!
Extra details
You can also specify the "main function" to run on the command line. Since the name of the default "main function" is
-main
, you can telllein run
the namespace containing the-main
function by typing:If your "main function" is not
-main
, then type something likeWhen you have compilation failues (especially if macros are involved), it is always safest to delete all previous
*.class
files vialein clean
. If you don't, maybe one in a hundred times you will get very strange failures that cannot be explained.I find it safest to define and always use an alias:
The version with
do
is about 1 second faster thanlein clean; lein run
, but don't forget the comma!How to avoid
OK, I just remembered a way to avoid the problem. Just type:
This will include the line
which was missing when you just type
lein new myproj
(i.e. with out theapp
part).