Intellij idea 用草书运行Clojure项目

Intellij idea 用草书运行Clojure项目,intellij-idea,clojure,cursive,Intellij Idea,Clojure,Cursive,我正在尝试用IntelliJ\Cursive运行一个简短的Clojure程序。 我的程序包括两个文件: project.clj: (defproject try3 "0.1.0-SNAPSHOT" :description "FIXME: write description" :url "http://example.com/FIXME" :license {:name "Eclipse Public License" :url "http://www.ecl

我正在尝试用IntelliJ\Cursive运行一个简短的Clojure程序。 我的程序包括两个文件:

project.clj:

(defproject try3 "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME"
  :license {:name "Eclipse Public License"
            :url "http://www.eclipse.org/legal/epl-v10.html"}
  :dependencies [[org.clojure/clojure "1.7.0"]]
  :main try3.core)
(ns try3.core)

(defn foo
  "I don't do a whole lot."
  [x]
  (println x "Hello, World!"))

(defn -main [] (println "hi"))
以及:

core.clj:

(defproject try3 "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME"
  :license {:name "Eclipse Public License"
            :url "http://www.eclipse.org/legal/epl-v10.html"}
  :dependencies [[org.clojure/clojure "1.7.0"]]
  :main try3.core)
(ns try3.core)

(defn foo
  "I don't do a whole lot."
  [x]
  (println x "Hello, World!"))

(defn -main [] (println "hi"))

我希望在运行项目时,-main函数将自动运行。我该怎么做才能做到这一点

我假设您希望在IDEA中创建运行配置。另外,
-main
方法告诉您可能尝试创建可运行类。为了实现这一点,您需要修改名称空间声明:

(ns try3.core
  (:gen-class))
; note :gen-class above. It tells clojure that file is intended to 
; be compiled into class instead of be running as a script.

然后您需要创建应用程序类型的IDEA运行配置。将命名空间指定为主类。请查看中的屏幕截图和评论。此外,您可能需要修改“编译器”>“Clojure编译器”设置,并在此处设置“编译所有Clojure命名空间”。完成这些步骤后,您应该具有可运行配置

我必须更改IntelliJ中的运行配置,才能让程序打印Hello World字符串。 打开运行>编辑配置。。。 如果未完成,请添加测试程序,并确保配置启用了Run-main from Clojure命名空间


您检查过了吗?你的代码看起来不错。启动leiningen并运行您的项目。我想知道为什么每个项目都必须手动完成。人们很自然地会认为人们会希望运行他们的项目。我遗漏了什么吗?也许你已经知道了:Ctrl-Shift-R运行当前打开的文件。如果您的文件有一个main,那么它旁边应该有一个绿色箭头,以便方便地运行它。这还将创建一个临时运行配置,然后可以保存该配置。在项目导航栏中的文件上单击鼠标右键将显示一些运行选项。