简体   繁体   English

Clojure lein uberjar:java.lang.ClassNotFoundException

[英]Clojure lein uberjar: java.lang.ClassNotFoundException

I have a Clojure library that has two gen-class directives. 我有一个Clojure库,其中有两个gen-class指令。 When I run lein run , there are no issues. 当我运行lein run ,没有任何问题。 However, when I run lein uberjar , I get errors: 但是,当我运行lein uberjar ,出现错误:

$ 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

In addition to the generated java files, there is the project.clj , server.clj , and core.clj . 除了生成的Java文件之外,还有project.cljserver.cljcore.clj

project.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 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 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))

It's weird because this was working and I think the compile-time order changed and now I cannot generate a standalone jar. 这很奇怪,因为这是可行的,而且我认为编译时顺序已更改,现在我无法生成独立的jar。

:profiles {:uberjar {:aot :all}} means that when you run uberjar it will try to compile all Namespaces. :profiles {:uberjar {:aot:all}}意味着当您运行uberjar时,它将尝试编译所有命名空间。 When you do lein run it only compiles the namespace in the :aot key. 当您运行lein时,它只会在:aot键中编译名称空间。

Try to update the uberjar profile to only aot the server namespace and see if that works. 尝试将uberjar配置文件更新为仅用于服务器名称空间,然后查看是否可行。

If not, message me and I'll dig into it deeper 如果没有,给我发消息,我会深入研究

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM