4

IntelliJ\Cursive で短い Clojure プログラムを実行しようとしています。私のプログラムには2つのファイルが含まれています:

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 関数が自動的に実行されます。これを実現するにはどうすればよいですか?

4

2 に答える 2

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.

次に、アプリケーションタイプの IDEA 実行構成を作成する必要があります。名前空間をメイン クラスとして指定します。このツイートのスクリーンショットとコメントをご覧ください。また、"Compiler" > "Clojure Compiler" の設定を変更し、そこで "Compile all Clojure namespaces" を設定する必要がある場合もあります。これらの手順の後、実行可能な構成が必要です。

于 2016-02-09T22:21:35.900 に答える