slf4j - slf4j 绑定(bind)错误

标签 slf4j gate

我正在使用 GATE 工具进行文本分析,在安装 PR 时出现以下错误-

SLF4J:您的 slf4j 绑定(bind)请求的版本 1.5.6 与 [1.6, 1.7] 不兼容

现在,我已经在互联网上搜索了这个并找到了这个 -

 Mixing different versions of slf4j-api.jar and SLF4J binding can cause problems. For example, if you are using slf4j-api-1.7.2.jar, then you should also use slf4j-simple-1.7.2.jar, using slf4j-simple-1.5.5.jar will not work.

我正在使用 slf4j-api-1.7.12 ,但是我的计算机上不存在此文件 slf4j-simple-N 。
我该如何解决这个问题?
任何帮助将不胜感激。谢谢!

最佳答案

编辑: GATE 8.4 中不再存在此问题 ,其中 GATE 中的类加载确实允许每个插件是独立的,因此一个插件加载的库不会干扰另一个插件加载的库。

问题

我想,我可以重现这个问题。
当两个插件被加载并且每个插件都使用不同版本的 slf4j-api 时,它会在 GATE Developer 中显现。 .例如 本体 插件正在使用 slf4j 1.5.6 Stanford_CoreNLP slf4j 1.7.12 .

尝试创建 的新实例时斯坦福 POS 标记器 ,它最终会出现以下错误消息(请参阅下面的完整日志):

java.lang.LinkageError: loader constraint violation: when resolving method "org.slf4j.impl...


GATE 8.2 build 5482 started at Mon Jul 04 21:54:09 CEST 2016
and using Java 1.8.0_91 Oracle Corporation on Windows 8.1 amd64 6.3.
CREOLE plugin loaded: file:/C:/Program%20Files/gate-8.2-build5482-BIN/plugins/Stanford_CoreNLP/
CREOLE plugin loaded: file:/C:/Program%20Files/gate-8.2-build5482-BIN/plugins/Ontology/
org.xml.sax.helpers.DefaultHandler is available via both the system classpath and a plugin; the plugin classes will be ignored
SLF4J: The requested version 1.5.6 by your slf4j binding is not compatible with [1.6, 1.7]
SLF4J: See http://www.slf4j.org/codes.html#version_mismatch for further details.
java.lang.LinkageError: loader constraint violation: when resolving method "org.slf4j.impl.StaticLoggerBinder.getLoggerFactory()Lorg/slf4j/ILoggerFactory;" the class loader (instance of gate/util/GateClassLoader) of the current class, org/slf4j/LoggerFactory, and the class loader (instance of gate/util/GateClassLoader) for the method's defining class, org/slf4j/impl/StaticLoggerBinder, have different Class objects for the type org/slf4j/ILoggerFactory used in the signature
    at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:335)
    at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:283)
    at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:304)
    at edu.stanford.nlp.io.IOUtils.<clinit>(IOUtils.java:42)
    at edu.stanford.nlp.tagger.maxent.MaxentTagger.readModelAndInit(MaxentTagger.java:765)
    at edu.stanford.nlp.tagger.maxent.MaxentTagger.<init>(MaxentTagger.java:298)
    at edu.stanford.nlp.tagger.maxent.MaxentTagger.<init>(MaxentTagger.java:263)
    at gate.stanford.Tagger.init(Tagger.java:129)
    at gate.Factory.createResource(Factory.java:432)
    at gate.gui.NewResourceDialog$4.run(NewResourceDialog.java:270)
    at java.lang.Thread.run(Unknown Source)

解决方案

我能想到三种可能的解决方案:

1)消除不必要的插件

你真的需要两个不兼容版本的 slf4j 插件吗?如果没有,只需卸载您不需要的插件(肯定要重新启动 GATE),问题应该就消失了。

2) 防止加载 的 slf4j jar一个 的插件

这个解决方案比下一个更脏(因为修改后的插件不能单独工作),但作为一个快速修复应该足够了。选择其中一个插件并从插件的 creole.xml 中删除 slf4j 条目文件。同样,GATE 重启后问题应该消失了。

对于 来说,这很容易。本体 插件:(注意注释掉的行)

<?xml version="1.0"?>
<CREOLE-DIRECTORY> 
      <JAR>lib/commons-httpclient-3.1.jar</JAR>
      <JAR>lib/owlim-lite-5.4.jar</JAR>
<!--  <JAR>lib/slf4j-api-1.5.6.jar</JAR>
      <JAR>lib/slf4j-jdk14-1.5.6.jar</JAR> -->
      <JAR>lib/openrdf-sesame-2.7.9-onejar.jar</JAR>
      <JAR SCAN="true">Ontology.jar</JAR>
</CREOLE-DIRECTORY>

对于 Stanford_CoreNLP 插件,它更复杂,因为它使用 Apache Ivy 加载 slf4j jar,并且必须在 ivy.xml 中排除它们文件( plugins\Stanford_CoreNLP\build\ivy.xml ,注意文件底部添加的行 <exclude org="org.slf4j"/> )

<ivy-module version="2.0">

  <info
    organisation="uk.ac.gate.plugins"
    module="stanford_corenlp"
    revision="8.2-SNAPSHOT">
    <description homepage="https://github.com/GateNLP/gateplugin-Stanford_CoreNLP/" />
  </info>

  <configurations>
    <conf name="default" />
  </configurations>

  <dependencies defaultconf="*->master(default),runtime(default)" >
    <dependency org="edu.stanford.nlp" name="stanford-corenlp" rev="3.6.0" />
    <exclude org="org.slf4j"/>
  </dependencies>
</ivy-module>

3)统一冲突的slf4j版本

这似乎是一个干净的解决方案,但它比我预期的要复杂得多,因为即使在两个插件使用相同版本的 slf4j 之后问题仍然存在。问题可能存在于 GATE 类加载机制的更深处,唯一“为我工作的方式”如何统一 slf4j 版本是在所有冲突的插件中排除它们并添加 slf4j jar(例如来自 Ontology 插件的那些) ) 到 GATE 的 lib文件夹。

关于slf4j - slf4j 绑定(bind)错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38041516/

相关文章:

java.lang.NoSuchMethodError : org. slf4j.spi.LocationAwareLogger.log(Lorg/slf4j/Marker;Ljava/lang/String;ILjava/lang/String;[Ljava/lang/Obje

java - 强制slf4j按顺序打印日志

java - GATE:将 Token.string 与宏进行比较

java - 将 logging.properties 文件更改为 Slf4j 中的不同路径

jboss7.x - org.slf4j.helpers.NOPLoggerFactory 不能转换为 ch.qos.logback.classic.LoggerContext

Javax.servlet.ServletException

java - 如何在 Gate 中创建 JAPE 语法规则

java - 门总和配置

java - 如何阅读自然语言处理GATE中的段落

javascript - 或者门 (||) 将 false 排序为未定义