slf4j的绑定错误 [英] Binding error with slf4j

查看:154
本文介绍了slf4j的绑定错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using a tool, GATE for text analysis and while installing a PR I get the following error-

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

SLF4J: The requested version 1.5.6 by your slf4j binding is not compatible with [1.6, 1.7]

现在,我已经在互联网上搜索了此内容,并找到了此内容

Now, I have searched the internet regarding this and have found this-

 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在我的计算机上不存在. 我该如何解决这个问题? 任何帮助将不胜感激.谢谢!

I am using slf4j-api-1.7.12 , but this file- slf4j-simple-N does not exist on my computer. How can I resolve this problem? Any help will be apprecited. Thanks!

推荐答案

该问题不再存在于GATE 8.4中,其中GATE中的类加载确实允许将每个插件分开,因此库一个插件加载的内容不会干扰另一个插件加载的内容.

the problem no longer exists in GATE 8.4, where the classloading in GATE does allow each plugin to be separate and so libraries loaded by one plugin do not interfere with those loaded by another plugin.

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

I think, I can reproduce the problem. It is manifesting in the GATE Developer when two plugins are loaded and each of them is using a different version of slf4j-api. For example the Ontology plugin is using slf4j 1.5.6 and the Stanford_CoreNLP slf4j 1.7.12.

尝试创建 Stanford POS Tagger 的新实例时,它最终显示以下错误消息(请参见完整的日志行):

When trying to create a new instance of Stanford POS Tagger, it ends up with following error message (see the full log bellow):

java.lang.LinkageError:违反加载程序约束:解决方法"org.slf4j.impl ...

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)

解决方案

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

Solution

There are three possible solutions I can think of:

您真的需要两个不兼容的slf4j版本的插件吗?如果没有,只需卸载不需要的插件(请确保重新启动GATE),问题就应该解决了.

Do you really need both plugins with the incompatible versions of slf4j? If not, simply unload the plugin you don't need (restart GATE for sure) and the problem should be gone.

此解决方案比下一个解决方案要脏得多(因为修改后的插件无法单独使用),但作为快速解决方案就足够了.选择一个插件,然后从插件的creole.xml文件中删除slf4j条目.同样,在GATE重新启动后,该问题仍将消失.

This a bit more dirty solution than the next one (because the modified plugin will not work alone) but it should be enough as a quick fix. Choose one of the plugins and remove slf4j entries from the plugin's creole.xml file. Again, the problem should be gone after GATE restart.

对于 Ontology 插件,这非常容易:(请注意注释掉的行)

This is quite easy for the Ontology plugin: (note the commented out lines)

<?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文件中(,请注意文件底部添加的行<exclude org="org.slf4j"/>)

For the Stanford_CoreNLP plugin, it is more complicated because it is loading slf4j jars using Apache Ivy and they have to be excluded in the ivy.xml file (plugins\Stanford_CoreNLP\build\ivy.xml, note the added line <exclude org="org.slf4j"/> at the bottom of the file)

<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插件的jar) )到GATE的lib文件夹.

这篇关于slf4j的绑定错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆