解决“多个Jar文件”又称“来自多个位置的扫描”。

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

Resolving "Multiple Jar files" aka "scanned from multiple locations"

问题

以下是翻译好的内容:

我正在处理一个喷射服务,当我启动它时,我得到很多类似这样的信息:

SomeClass 从多个位置扫描:jar: jar1!Someclass.class, jar2!Someclass.class

因此,同一个类由两个 JAR 提供,在运行时获取的是不确定的,这是不好的。看了其他问题后,我发现 tattletale 可以帮助诊断这个问题。报告中,在 多个 Jar 文件 部分列出了与 jetty 在启动时相同的类,以及它们所在的 JAR。

冲突的子集如下:

解决“多个Jar文件”又称“来自多个位置的扫描”。

并且在运行以下命令后:

mvn dependency:tree -D verbose

我得到:

+- ca.uhn.hapi.fhir:hapi-fhir-jpaserver-base:jar:3.7.0:compile
|  |                   ...
|  +- org.jscience:jscience:jar:4.3.1:compile
|  |  \- org.javolution:javolution:jar:5.2.3:compile

所以,似乎我的 fhir-base-jpaserver-base 依赖会拉取 jscience,而 jscience 又会拉取 javolution。但是 jscience 和 javolution 提供了一些相同的类。没有其他对 javolution 的依赖。

我的问题是,我应该如何解决这个问题?

我可以在 pom.xml 中使用一些<exclude>来处理,但我想 jscience 可能需要 javolution,这样做可能会有问题吗?

英文:

I am working on a jetty service, and when starting it, I get a lot of:

SomeClass scanned from multiple locations: jar: jar1!Someclass.class, jar2!Someclass.class

So a single class is provided by two jars, and which I get on runtime is undefined, which is not good. Looking at other issues I found that tattletale can help diagnosing the problem. The report, in the Multiple Jar files section lists the same classes as jetty upon startup and which jars they were in.
A subset of the conflicts are:

解决“多个Jar文件”又称“来自多个位置的扫描”。

And looking at

mvn dependency:tree -D verbose

I get:

+- ca.uhn.hapi.fhir:hapi-fhir-jpaserver-base:jar:3.7.0:compile
|  |                   ...
|  +- org.jscience:jscience:jar:4.3.1:compile
|  |  \- org.javolution:javolution:jar:5.2.3:compile

And so it seems that my fhir-base-jpaserver-base dependency pulls jscience that pulls javolution. But jscience and javolution supply some of the same classes. No other dependency to javolution exists.

My question is then, how do I go about solving this?

I could do some <exclude> stuff in pom.xml but I suppose jscience needs javolution, and might break?

答案1

得分: 0

听起来像是jscience中的一个错误,与他们打包jar的方式有关,可能希望向他们报告问题。

他们应该要么...

  • 有一个适当/集中的jar和依赖关系。
  • 要么有一个独立的超级jar,没有依赖关系。

不要混淆这两个概念。

同时,只需使用<dependency>/<exclusions>来排除导致重复类的特定传递性依赖关系。

另外,您可能希望运行任何一个多重类/资源检查器Maven插件,以查找您的项目中可能存在的其他情况。

英文:

Sounds like a bug in jscience with how they packaged their jar, might want to file an issue with them.

They should either ...

  • have a proper/focused jar and dependencies.
  • or a standalone uber jar with no dependencies.

Not mixing the two concepts.

Meanwhile, just use the &lt;dependency&gt;/&lt;exclusions&gt; to exclude specific transitive dependencies that are causing you duplicate classes.

Also, you might want to run any of the various duplicate class/resource checker maven plugins to find any other cases you might have present on your project.

huangapple
  • 本文由 发表于 2020年10月9日 14:01:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/64274684.html
匿名

发表评论

匿名网友

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

确定