英文:
Resolving "Multiple Jar files" aka "scanned from multiple locations"
问题
以下是翻译好的内容:
我正在处理一个喷射服务,当我启动它时,我得到很多类似这样的信息:
SomeClass 从多个位置扫描:jar: jar1!Someclass.class, jar2!Someclass.class
因此,同一个类由两个 JAR 提供,在运行时获取的是不确定的,这是不好的。看了其他问题后,我发现 tattletale 可以帮助诊断这个问题。报告中,在 多个 Jar 文件 部分列出了与 jetty 在启动时相同的类,以及它们所在的 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:
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 <dependency>/<exclusions>
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论