使用cljfx时lein deps执行失败的问题求助
解决Leiningen下载cljfx依赖时找不到OpenJFX平台jar的问题
问题原因
你遇到的错误是因为cljfx依赖的OpenJFX使用了Maven属性${javafx.platform}指定平台分类器,但Leiningen默认不会自动解析这个变量,导致无法找到对应平台的jar包。OpenJFX的jar包按操作系统(linux/mac/windows等)分类发布,必须明确指定分类器才能下载到正确的依赖。由于你使用的是OpenBSD amd64,OpenJFX官方没有提供专门的包,可使用兼容的linux分类器替代。
解决方案1:添加Maven属性指定平台
修改你的project.clj,新增:properties配置设置javafx.platform的值:
(defproject ui "0.1.0-SNAPSHOT" :description "FIXME: write description" :url "http://example.com/FIXME" :license {:name "EPL-2.0 OR GPL-2.0-or-later WITH Classpath-exception-2.0" :url "https://www.eclipse.org/legal/epl-2.0/"} :properties {:javafx.platform "linux"} ; 指定平台分类器 :dependencies [[org.clojure/clojure "1.11.1"] [cljfx "1.7.24"]] :main ^:skip-aot ui.core :target-path "target/%s" :profiles {:uberjar {:aot :all :jvm-opts ["-Dclojure.compiler.direct-linking=true"]}})
修改后执行lein deps尝试下载依赖。
解决方案2:显式添加带分类器的OpenJFX依赖
如果方案1无效,可排除cljfx传递的OpenJFX依赖,手动添加带linux分类器的版本:
(defproject ui "0.1.0-SNAPSHOT" :description "FIXME: write description" :url "http://example.com/FIXME" :license {:name "EPL-2.0 OR GPL-2.0-or-later WITH Classpath-exception-2.0" :url "https://www.eclipse.org/legal/epl-2.0/"} :dependencies [[org.clojure/clojure "1.11.1"] [cljfx "1.7.24" :exclusions [org.openjfx/javafx-controls org.openjfx/javafx-base org.openjfx/javafx-graphics org.openjfx/javafx-media org.openjfx/javafx-web]] [org.openjfx/javafx-controls "19.0.2.1" :classifier "linux"] [org.openjfx/javafx-base "19.0.2.1" :classifier "linux"] [org.openjfx/javafx-graphics "19.0.2.1" :classifier "linux"] [org.openjfx/javafx-media "19.0.2.1" :classifier "linux"] [org.openjfx/javafx-web "19.0.2.1" :classifier "linux"]] :main ^:skip-aot ui.core :target-path "target/%s" :profiles {:uberjar {:aot :all :jvm-opts ["-Dclojure.compiler.direct-linking=true"]}})
验证步骤
执行lein clean清理本地缓存,再运行lein deps,检查是否能成功下载所有依赖。
内容的提问来源于stack exchange,提问作者Lucas Moreira
相关产品推荐
相关产品推荐

