Binding error with slf4j

后端 未结 2 1751
旧巷少年郎
旧巷少年郎 2021-01-20 01:16

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

SLF4J: The requested version 1.5.6 by your slf4j binding is not compat

2条回答
  •  时光说笑
    2021-01-20 02:16

    Edit: 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.


    Problem

    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.

    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: 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.(IOUtils.java:42)
        at edu.stanford.nlp.tagger.maxent.MaxentTagger.readModelAndInit(MaxentTagger.java:765)
        at edu.stanford.nlp.tagger.maxent.MaxentTagger.(MaxentTagger.java:298)
        at edu.stanford.nlp.tagger.maxent.MaxentTagger.(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:

    1) Eliminate unnecessary plugins

    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.

    2) Prevent loading of slf4j jars of ONE of the plugins

    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.

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

    
     
          lib/commons-httpclient-3.1.jar
          lib/owlim-lite-5.4.jar
    
          lib/openrdf-sesame-2.7.9-onejar.jar
          Ontology.jar
    
    

    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 at the bottom of the file)

    
    
      
        
      
    
      
        
      
    
      
        
        
      
    
    

    3) Unify the conflicting slf4j versions

    This seems to be a clean solution but it is much more complicated than I expected, because the problem remains even after both the plugins use the same version of slf4j. The problem probably lies deeper inside of the GATE class-loading mechanism and the only "working for me way" how to unify the slf4j versions was to exclude them in all the conflicting plugins and to add the slf4j jars (e.g. those from the Ontology plugin) to the GATE's lib folder.

提交回复
热议问题