Clojure Ahead-of-Time compilation fails for Java classes "No matching method ofInstant found taking 2 args for class java.time.LocalDate"

huangapple go评论71阅读模式
英文:

Clojure Ahead-of-Time compilation fails for Java classes "No matching method ofInstant found taking 2 args for class java.time.LocalDate"

问题

尝试使用clj -e "(compile 'my-ns.core)"对Clojure命名空间进行AOT编译,在尝试构造LocalDate时抛出异常:

语法错误 (IllegalArgumentException) 编译 . 位于 (my-project/my-ns-core.clj:5:1)。
找不到匹配的 ofInstant 方法,接受 2 个参数,用于 java.time.LocalDate 类

在REPL中正常工作。为什么AOT编译会失败?已经导入了类。

(ns my-ns.core
  (:require [clojure.alpha.spec.gen :as g])
  (:import (java.time LocalDate))

(LocalDate/ofInstant (Instant/ofEpochMilli 123) (ZoneId/of "UTC"))

我认为这可能与从AOT构建中包含了这些类有关?

英文:

Attempting to AOT compile a Clojure namespace with clj -e "(compile 'my-ns.core)" throws an exception when attempting to construct a LocalDate:

Syntax error (IllegalArgumentException) compiling . at (my-project/my-ns-core.clj:5:1).
No matching method ofInstant found taking 2 args for class java.time.LocalDate

Works fine in REPL. Why failing in AOT? Classes are imported.

(ns my-ns.core
  (:require [clojure.alpha.spec.gen :as g])
  (:import (java.time LocalDate))

(LocalDate/ofInstant (Instant/ofEpochMilli 123) (ZoneId/of "UTC"))

I assume this must be related to these classes being included from the AOT build?

答案1

得分: 1

GraalVM在我的$PATH中,优先于调用具有不包括Java 8日期类的较旧Java版本的java命令。通过运行which java找出了问题所在。

解决方法是:

export JAVA_HOME=/Users/<username>/Library/Java/JavaVirtualMachines/openjdk-15/Contents/Home

并且不在$PATH中包含$GRAALVM_HOME

英文:

GraalVM was in my $PATH which took precedence for calls to java with an older Java version that did not include the Java 8 date classes. Figured it out by running which java.

Solved with:

export JAVA_HOME=/Users/&lt;username&gt;/Library/Java/JavaVirtualMachines/openjdk-15/Contents/Home`

And not including $GRAALVM_HOME in $PATH.

huangapple
  • 本文由 发表于 2020年10月21日 23:12:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/64466618.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定