英文:
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/<username>/Library/Java/JavaVirtualMachines/openjdk-15/Contents/Home`
And not including $GRAALVM_HOME
in $PATH
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论