首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Clojure中创建Uberjar时出现的问题

在Clojure中创建Uberjar时出现的问题
EN

Stack Overflow用户
提问于 2020-10-07 12:06:35
回答 1查看 510关注 0票数 3

我正在使用Clojure的java-time库,它是java.time 1的包装器。

当我调用lein run或通过repl调用函数时,我的程序就工作了。另一方面,当我尝试执行lein uberjar时,涉及的类会出现以下错误:

代码语言:javascript
复制
$ lein uberjar
Compiling foo.cli
Compiling foo.core
Compiling foo.holidays
nil
Syntax error (ClassCastException) compiling at (/tmp/form-init8528909580728167374.clj:1:73).
class java_time.graph.Types cannot be cast to class java_time.graph.Types (java_time.graph.Types is in unnamed module of loader 'app'; java_time.graph.Types is in unnamed module of loader clojure.lang.DynamicClassLoader @141c66db)

Full report at:
/tmp/clojure-6795557396101417445.edn
Compilation failed: Subprocess failed

我已经分离出是哪个表达式导致了这个问题,而它恰好是:

代码语言:javascript
复制
(java-time/minus  (java-time/local-date) (java-time/period 2 :days))

我不知道它为什么会失败,而且这个错误是相当神秘的。我敢打赌,编译器在生成uberjar时会混淆某些类,但令我惊讶的是,repl工作得很好。它与用于创建uberjar的:aot有关吗?

这是关于以下内容的project.clj文件片段:

代码语言:javascript
复制
(defproject foo
  ...
  :main ^:skip-aot foo.core
  :target-path "target/%s"
  :profiles {:uberjar {:aot :all
                       :jvm-opts ["-Dclojure.compiler.direct-linking=true"]}})

1

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-10-07 14:47:42

看来你在你的环境中出了点问题。一个示例程序对我来说很好:

代码语言:javascript
复制
    (ns demo.core
      (:use tupelo.core)
      (:require [java-time :as jt])
      (:gen-class))
    
    (defn -main [& args]
      (print-versions)
      (let [result (java-time/minus
                     (java-time/local-date)
                     (java-time/period 2 :days))]
        (println :result result)))

其结果是:

代码语言:javascript
复制
    ~/expr/demo > lein clean ; lein run
    
    --------------------------------------
       Clojure 1.10.2-alpha1    Java 15
    --------------------------------------
    :result #object[java.time.LocalDate 0x61a309fe 2020-10-05]
    
    
    ~/expr/demo > lein clean ; lein uberjar 
    Compiling demo.core
    Created /home/alan/expr/demo/target/uberjar/demo-0.1.0-SNAPSHOT.jar
    Created /home/alan/expr/demo/target/uberjar/demo-0.1.0-SNAPSHOT-standalone.jar

为了完整起见,下面是project.clj

代码语言:javascript
复制
(defproject demo "0.1.0-SNAPSHOT"
  :license {:name "Eclipse Public License"
            :url  "http://www.eclipse.org/legal/epl-v10.html"}
  :dependencies [
                 [clojure.java-time "0.3.2"]
                 [org.clojure/clojure "1.10.2-alpha1"]
                 [prismatic/schema "1.1.12"]
                 [tupelo "20.08.27"]
                 ]
  :plugins [
            [com.jakemccrary/lein-test-refresh "0.24.1"]
            [lein-ancient "0.6.15"]
            [lein-codox "0.10.7"]
            ]

  :profiles {:dev     {:dependencies []}
             :uberjar {:aot :all}}

  :global-vars {*warn-on-reflection* false}
  :main ^:skip-aot demo.core

  :source-paths ["src/clj"]
  :java-source-paths ["src/java"]
  :test-paths ["test/clj"]
  :target-path "target/%s"
  :compile-path "%s/class-files"
  :clean-targets [:target-path]

  :jvm-opts ["-Xms500m" "-Xmx4g"]
  )
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64243685

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档