次のような hello.clj があります。
(ns hello)
(defn hi [] (println "HI"))
通常、この関数は main.clj から次のように使用できます。hello.clj は、main.clj と同じディレクトリにあります。また、クラスパスには . (現在のパス)。
(use 'hello)
(hi)
この hello.clj を「lein uberjar」に使用するにはどうすればよいですか?
私は「lein new myproject;」を使用しました。lein deps' を実行して、次の構造を取得します。
. |-- README |-- クラス | | `-- 私のプロジェクト |-- ライブラリ | | |-- clojure-1.2.0-beta1.jar | | |-- clojure-contrib-1.2.0-beta1.jar | | `-- lucene-core-3.0.2.jar |-- project.clj |-- ソース | | `-- 私のプロジェクト | | ` -- core.clj `-- テスト `-- 私のプロジェクト `-- テスト ` -- core.clj
project.clj は次のとおりです。
(defproject myproject "1.0.0-SNAPSHOT"
:description "FIXME: write"
:dependencies [[org.clojure/clojure "1.2.0-beta1"]
[org.clojure/clojure-contrib "1.2.0-beta1"]
[org.apache.lucene/lucene-core "3.0.2"]]
:main myproject.core)
そして、core.clj は次のとおりです。
(ns myproject.core
(:gen-class))
(use 'hello)
(defn test1 [] (println "hello"))
(defn -main [& args]
(do
(println "Welcome to my project! These are your args:" args)
(test1)
(hi)))
では、hello.clj はどこに置くのでしょうか。それを myproject/src ディレクトリにコピーし、uberjar を実行して jar を取得しようとしました。ただし、jar を実行すると、このエラー メッセージが表示されます。
prosseek:myproject smcho$ java -jar myproject-1.0.0-SNAPSHOT-standalone.jar を追加 スレッド「メイン」での例外 java.lang.ExceptionInInitializerError 原因: java.io.FileNotFoundException: クラスパスに hello__init.class または hello.clj が見つかりませんでした: (core.clj:0) ...
- 何が間違っている可能性がありますか? エラー メッセージには、hello.clj がクラス パスにないことが示されています。しかし、「lein uberjar」でクラスパスをセットアップする方法は?
ここにプロジェクトをアップロードしました。