在Cursive中运行Clojure项目

时间:2016-01-29 16:27:25

标签: 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.eclipse.org/legal/epl-v10.html"}
  :dependencies [[org.clojure/clojure "1.7.0"]]
  :main try3.core)

core.clj:

(ns try3.core)

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

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

我希望在运行项目时,-main函数会自动运行。我该怎么做才能实现这一目标?

2 个答案:

答案 0 :(得分:0)

我假设你想在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.

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

答案 1 :(得分:0)

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

IntelliJ screenshot

相关问题