简体   繁体   English

使用具有不兼容依赖性的Java库

[英]Using Java Libraries With Incompatible Dependencies

I'm working on a project where I'd like to use Apache Tika and Apache Jena. 我正在一个项目中使用Apache Tika和Apache Jena。 However, when I try to run the project I get the following exception: 但是,当我尝试运行项目时,出现以下异常:

java.lang.NoSuchMethodError: org.slf4j.spi.LocationAwareLogger.log Lorg/slf4j/Marker;Ljava/lang/String;ILjava/lang/String; Ljava/lang/Object;Ljava/lang/Throwable;)V

My understanding is that this is because Apache Tika includes an old version of SLF4J (pre 1.6.0) and Apache Jena includes a newer version (1.6.0 or later), and that there is a breaking change between the two versions of SLF4J. 我的理解是,这是因为Apache Tika包含旧版本的SLF4J(1.6.0之前的版本),而Apache Jena包含了较新的版本(1.6.0或更高版本),并且两个版本的SLF4J之间存在重大变化。

How do I get around this issue so that I can use both Tika and Jena at the same time? 如何解决此问题,以便可以同时使用Tika和Jena?

Some existing posts talk about using Maven to work around this, but a) I don't use Maven and I'm not familiar enough with it to fully understand the solutions and b) I'm working on a development network that isn't connected to the internet. 现有的一些文章谈论使用Maven解决此问题,但是a)我不使用Maven,并且我对Maven不够熟悉,无法完全理解解决方案; b)我正在开发的开发网络不连接到互联网。

slf4j is actually fairly compatible across versions for many usages. slf4j实际上在许多用途的各个版本之间都相当兼容。 Jena does not use many features of SLF4j. 耶拿(Jena)没有使用SLF4j的许多功能。 It does not LocationAwareLogger as far as I'm aware. 据我所知,它没有LocationAwareLogger。 It may work with pre 1.6.X. 它可能适用于1.6.X之前的版本。 While nothing is guaranteed (AKA you have to test it), it's worth a try. 虽然没有什么可以保证的(又要测试),但是值得一试。

If that fails, you'll need to rebuild one system and tweak what needs to be changed. 如果失败,则需要重建一个系统并调整需要更改的内容。 Both systems are open source with both code and build system is available. 这两个系统都是带有代码的开放源代码,并且可以使用构建系统。

I wouldn't use these 2 libraries until they have the same version unless I'm absolutely have to do that. 除非我绝对必须这样做,否则在它们具​​有相同版本之前,我不会使用这两个库。

If you think so, then a good explanation of the issue is here: java-classpath-classloading-multiple-versions-of-the-same-jar-project 如果您这样认为,那么这里的问题就可以得到很好的解释: java-classpath-classloading-multiple-versions-of-the-same-jar-project

解决方案是更改库的顺序,以使具有新版本SLF4J(Apache Jena)的库在构建路径上早于旧版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM