2017-11-23 8 views
0

2つのgen-classディレクティブを持つClojureライブラリがあります。 lein runを実行しても問題はありません。しかし、私はlein uberjarを実行すると、私はエラーを取得:Clojureクラスライブラリ:java.lang.ClassNotFoundException

$ lein uberjar 
Compiling 6 source files to /Users/frank/src/user/target/uberjar/classes 
Compiling user.common 
Compiling user.core 
java.lang.ClassNotFoundException: user.server.UserAuthenticationServer, compiling:(user/core.clj:15:30) 
Exception in thread "main" java.lang.ClassNotFoundException: user.server.UserAuthenticationServer, compiling:(user/core.clj:15:30) 
    at clojure.lang.Compiler.analyzeSeq(Compiler.java:6926) 
..... 
    at clojure.lang.Compiler.analyze(Compiler.java:6701) 
Caused by: java.lang.ClassNotFoundException: user.server.UserAuthenticationServer 
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381) 
... 
    at clojure.lang.Compiler.analyzeSeq(Compiler.java:6919) 
    ... 86 more 

生成されたJavaファイルに加えて、project.cljserver.clj、およびcore.cljがあります。

project.clj

(defproject user "0.1.0-SNAPSHOT" 
    :dependencies [[org.clojure/clojure      "1.9.0-alpha14"] 
       [io.grpc/grpc-core       "1.7.0"] 
       [io.grpc/grpc-netty       "1.7.0" 
        :exclusions [io.grpc/grpc-core]] 
       [io.grpc/grpc-protobuf      "1.7.0"] 
       [io.grpc/grpc-stub       "1.7.0"]] 
    :main ^:skip-aot user.core 
    :aot [user.server] 
    :target-path "target/%s" 
    :source-paths ["src/clj"] 
    :java-source-paths ["src/generated/proto" 
         "src/generated/grpc"] 
    :profiles {:uberjar {:aot :all}}) 

core.clj

(ns user.core 
    (:import [io.grpc Server ServerBuilder]) 
    (:gen-class)) 

(defonce start-server-atom (atom nil)) 
(def port     8080) 

(defn start-server [] 
    (when-not @start-server-atom 
    (reset! start-server-atom 
      (-> (ServerBuilder/forPort port) 
       (.addService (new user.server.UserAuthenticationServer)) 
       .build 
       .start 
       .awaitTermination)))) 

(defn -main 
    [& args] 
    (start-server)) 

server.clj

(ns user.server 
    (:gen-class 
    :main false 
    :name user.server.UserAuthenticationServer 
    :extends xyz.skroo.user.UserAuthenticationGrpc$UserAuthenticationImplBase)) 

(defn -startUserAuthentication [this req res] 
    (.onNext res req) 
    (.onCompleted res)) 

このワットので、それは奇妙ですコンパイル時の順序が変更されたと思うので、スタンドアロンのjarファイルを生成することはできません。

答えて

2

:profiles {:uberjar {:aot:all}}は、uberjarを実行するとすべての名前空間をコンパイルしようとします。 Leinを実行すると、:aotキーの名前空間だけがコンパイルされます。

uberjarプロファイルを更新して、サーバーの名前空間のみを確認し、それが機能するかどうか確認してください。

私にメッセージをすれば、より深く掘り下げよう。

+0

それはうまくいった! uberjar aotベクトルに 'user.core'と' user.server'の両方を追加しました。 – frank

関連する問題