jlink失败了ring-json 0.5.1
我有一个带有/project.clj
的小型Clojure项目:
(defproject testjackson "0.1.0-SNAPSHOT"
:main testjackson.core
:dependencies [[org.clojure/clojure "1.10.3"]
[ring/ring-json "0.5.0"]])
和/src/testjackson/core.clj
:
(ns testjackson.core
(:gen-class)
(:require [ring.middleware.json :refer [wrap-json-body]]))
(defn -main [& _] (println :testing wrap-json-body))
当我运行它时,它只是打印:
$ java -jar target/testjackson-0.1.0-SNAPSHOT-standalone.jar
:testing #object[ring.middleware.json$wrap_json_body 0x37cd92d6 ring.middleware.json$wrap_json_body@37cd92d6]
它按预期运行。我还可以执行
$ jdeps --print-module-deps --ignore-missing-deps target/testjackson-0.1.0-SNAPSHOT-standalone.jar
java.base,java.desktop,java.sql,jdk.unsupported
但是,当我碰到ring> ring-json
版本为0.5.1
时,JDEPS调用失败:
$ jdeps --print-module-deps --ignore-missing-deps target/testjackson-0.1.0-SNAPSHOT-standalone.jar
Exception in thread "main" java.lang.module.FindException: Module com.fasterxml.jackson.core not found, required by com.fasterxml.jackson.dataformat.smile
at java.base/java.lang.module.Resolver.findFail(Resolver.java:877)
at java.base/java.lang.module.Resolver.resolve(Resolver.java:191)
at java.base/java.lang.module.Resolver.resolve(Resolver.java:140)
at java.base/java.lang.module.Configuration.resolve(Configuration.java:422)
at java.base/java.lang.module.Configuration.resolve(Configuration.java:256)
at jdk.jdeps/com.sun.tools.jdeps.JdepsConfiguration$Builder.build(JdepsConfiguration.java:564)
at jdk.jdeps/com.sun.tools.jdeps.JdepsTask.buildConfig(JdepsTask.java:603)
at jdk.jdeps/com.sun.tools.jdeps.JdepsTask.run(JdepsTask.java:557)
at jdk.jdeps/com.sun.tools.jdeps.JdepsTask.run(JdepsTask.java:533)
at jdk.jdeps/com.sun.tools.jdeps.Main.main(Main.java:49)
如何在此小的上下文中修复示例程序?
I have a small Clojure project with /project.clj
:
(defproject testjackson "0.1.0-SNAPSHOT"
:main testjackson.core
:dependencies [[org.clojure/clojure "1.10.3"]
[ring/ring-json "0.5.0"]])
and /src/testjackson/core.clj
:
(ns testjackson.core
(:gen-class)
(:require [ring.middleware.json :refer [wrap-json-body]]))
(defn -main [& _] (println :testing wrap-json-body))
When I run it, it just prints:
$ java -jar target/testjackson-0.1.0-SNAPSHOT-standalone.jar
:testing #object[ring.middleware.json$wrap_json_body 0x37cd92d6 ring.middleware.json$wrap_json_body@37cd92d6]
It runs as expected. I can also execute jdeps on the uberjar to get the list of used modules:
$ jdeps --print-module-deps --ignore-missing-deps target/testjackson-0.1.0-SNAPSHOT-standalone.jar
java.base,java.desktop,java.sql,jdk.unsupported
However, when I bump ring-json
version to 0.5.1
, the jdeps call fails:
$ jdeps --print-module-deps --ignore-missing-deps target/testjackson-0.1.0-SNAPSHOT-standalone.jar
Exception in thread "main" java.lang.module.FindException: Module com.fasterxml.jackson.core not found, required by com.fasterxml.jackson.dataformat.smile
at java.base/java.lang.module.Resolver.findFail(Resolver.java:877)
at java.base/java.lang.module.Resolver.resolve(Resolver.java:191)
at java.base/java.lang.module.Resolver.resolve(Resolver.java:140)
at java.base/java.lang.module.Configuration.resolve(Configuration.java:422)
at java.base/java.lang.module.Configuration.resolve(Configuration.java:256)
at jdk.jdeps/com.sun.tools.jdeps.JdepsConfiguration$Builder.build(JdepsConfiguration.java:564)
at jdk.jdeps/com.sun.tools.jdeps.JdepsTask.buildConfig(JdepsTask.java:603)
at jdk.jdeps/com.sun.tools.jdeps.JdepsTask.run(JdepsTask.java:557)
at jdk.jdeps/com.sun.tools.jdeps.JdepsTask.run(JdepsTask.java:533)
at jdk.jdeps/com.sun.tools.jdeps.Main.main(Main.java:49)
How can this be fixed in the context of this small example program?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
就像从搜索中可以找到的那样,
jdeps
是从java 9中的路。 't甚至具有- 版本
选项。网络搜索没有显示Clojure的明显用途。这里的目标是什么?您的普通代码对我有效:
project.clj deps
代码
和结果
猜测,
尽管我的
jlink
似乎无法正常工作,但我可以猜测一点。查看project.clj
,我们可以要求一棵大树的树:因此,我们看到Ring-Json需要Cheshire,需要Jackson。
返回到Ring-json 0.5.0,我们看到了Cheshire和Jackson的不同版本:
请注意,如果需要,您可以在
Project.Clj
中强制较新版本。只是手动需要柴郡
和杰克逊
, 将它们放在顶部 !结果
可能会解决您的问题。过去对我来说一直至关重要。
具体来说,杰克逊libs 绝对必须
在同一版本上具有所有3个子图案。因为依赖的libs
通常,不要尽可能多地更新自己的杰克逊(Jackson)之类的人,而当两个或更多的libs都需要不同版本的杰克逊(Jackson)时,很容易遇到版本冲突。迫使杰克逊(或任何其他LIB)的特定版本的上述技术是救生员。恕我直言,它也比尝试放入一堆Lein
:Dextusions
子句要好得多。As near I as can find from searching,
jdeps
is from way back in Java 9. In fact, the version on my computer won't even accepts the 2 flags you used in the example, and it doesn't even have a--version
option. Web searching shows no obvious uses for clojure.What is the goal here? Your plain code works fine for me:
project.clj deps
code
and results
Speculation
Although my
jlink
doesn't seem to work right, I can guess a little. Looking atproject.clj
, we can ask for a tree of depencencies:So we see that ring-json needs cheshire, which needs jackson.
Going back to ring-json 0.5.0 we see different version of cheshire and jackson:
Note that you can force newer versions in
project.clj
if you want. Just manually requirecheshire
andjackson
, and put them near the top!with result
Perhaps something similar will solve your problem. It has been crucial for me in the past.
Specifically, the jackson libs absolutely must
have all 3 sub-libraries on the same version. Because dependent libs
often don't update their own deps like jackson as often as they could, it is easy to get version conflicts when 2 or more libs each require different versions of jackson. The above technique of forcing a specific version of jackson (or any other lib) is a lifesaver. IMHO, it is also much better than trying to put in a bunch of lein
:exclusions
clauses.