我在使用 com.fasterxml.aalto-xml 库时遇到问题。
我有一个项目 A (Dspace),它不依赖于库 com.fasterxml.aalto-xml。
我开发了一个库 B,它使用依赖于 com.fasterxml.aalto-xml 的库 C。
I wonder why when com.fasterxml.aalto-xml gets added as a dependency to A by way of B -> C, A picks up com.fasterxml.aalto-xml to do his usual XML Parsing.
问题是,它破坏了应用程序。 com.fasterxml.aalto-xml无法正确解析 A 最初附带的 XML。出了问题。
我想了解为什么会发生这种情况。有没有办法告诉A不要使用com.fasterxml.aalto-xml但仍然有 B -> C -> com.fasterxml.aalto-xml在 A 项目中工作。
这些 XML 解析器有什么特别之处?我只是不明白为什么 A 会选择 com.fasterxml.aalto-xml 来使用它,而它对此没有任何依赖。
我可以看到该lib也是一个osgi捆绑jar,这可能有什么含义吗?
I mean originally A (Dspace) works without alto and use whatever parser it has, why picking alto now that it is in the dependency ? what mechanism allow that ?
最佳答案
com.fasterxml:aalto-xml
包含 StAX API 的实现。该 API(从 Java 6 开始是 JRE 的一部分)使用 here 中描述的服务提供者发现机制。来定位实现。因此,只需将 Aalto JAR 添加到类路径即可更改 StAX API 使用的实现。所有使用 StAX API 的库(在您的例子中是 A 和 C)都将同样受到影响。
关于java - 当 com.fasterxml.aalto-xml 位于 Maven 依赖项中时解析 XML 时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32389842/