H2O.ai h2o-genmodel.jar包含sl4j绑定 [英] H2O.ai h2o-genmodel.jar contains sl4j binding

查看:82
本文介绍了H2O.ai h2o-genmodel.jar包含sl4j绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用h2o-genmodel.jar时(通过 maven Central 或生成mojo时输出)SLF4j给出错误

When using the h2o-genmodel.jar (either from maven central or that is output when generating a mojo) SLF4j gives the error

SLF4J:类路径包含多个SLF4J绑定
SLF4J:在[jar:file:〜/.ivy2/cache/org.slf4j/slf4j-log4j12/jars/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]中找到绑定> SLF4J:请参见 http://www.slf4j.org/codes.html#multiple_bindings 进行解释.

SLF4J: Class path contains multiple SLF4J bindings
SLF4J: Found binding in [jar:file:~/.ivy2/cache/org.slf4j/slf4j-log4j12/jars/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.

使用maven或SBT的传递依赖项排除不起作用,因此,现在我将jar输出与mojo一起使用,并手动从jar内部删除依赖项.

Using maven or SBT's transitive dependency exclusion doesn't work, so right now I'm using the jar output with the mojo and removing the dependencies from inside the jar by hand.

有没有更好的方法来使用h2o modelgen而不用手动弄乱jar的内部(最好使用maven代替)?

Is there some better way to use h2o modelgen without having to manually mess with the inside of the jar (using maven instead would be preferable)?

推荐答案

h2o-genmodel这是pom类型的依赖项.这意味着您可以将其用作多个依赖项的聚集器,以使您的生活更轻松.您的问题是由于h2o-genmodelai.h2o:deepwater-backend-api:jar:1.0.4依赖项具有对org.slf4j:slf4j-log4j12:jar:1.7.5的临时依赖关系这一事实引起的.您可以使用依赖项maven插件调试依赖项层次结构,运行以下命令:

h2o-genmodel it's a pom type dependency. That means you use it as an aggregator for multiple dependencies to make your life easier. Your problem arise from the fact that the ai.h2o:deepwater-backend-api:jar:1.0.4 dependency of h2o-genmodel has a transient dependency to org.slf4j:slf4j-log4j12:jar:1.7.5. You can debug the dependency hierarchy by using the dependency maven plugin, run the following command:

> mvn dependency:tree
...
[INFO] \- ai.h2o:h2o-genmodel:pom:3.18.0.11
[INFO]    +- net.sf.opencsv:opencsv:jar:2.3
[INFO]    +- com.google.code.gson:gson:jar:2.6.2
[INFO]    +- com.google.protobuf.nano:protobuf-javanano:jar:3.1.0
[INFO]    \- ai.h2o:deepwater-backend-api:jar:1.0.4
[INFO]       \- org.slf4j:slf4j-log4j12:jar:1.7.5
[INFO]          +- org.slf4j:slf4j-api:jar:1.7.5
[INFO]          \- log4j:log4j:jar:1.2.17

要解决此问题,可以使用以下方法从h2o-genmodel依赖项中排除slf4j-log4j12依赖项:

To fix this, you can exclude the slf4j-log4j12 dependency from h2o-genmodel dependency with this:

    <dependency>
        <groupId>ai.h2o</groupId>
        <artifactId>h2o-genmodel</artifactId>
        <version>3.18.0.11</version>
        <type>pom</type>
        <exclusions>
            <exclusion>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-log4j12</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

您可以再次运行maven依赖关系树命令来检查还剩下多少slf4j绑定.

You can run again the maven dependency tree command to check how many slf4j bindings remained.

因为该错误抱怨多个slf4j绑定,所以我假设一旦您确保在依赖项树中只有一个slf4j绑定,一切在运行时就可以了.

Because the error complains of multiple slf4j bindings I assume once you make sure there is only one slf4j binding in the dependency tree everything will be fine at runtime.

更新:

此解决方案有效的更多详细信息:
首先,将ai.h2o:h2o-genmodel依赖项声明为pom类型,因为这是它的发布方式. pom类型的Maven工件在两种情况下使用:作为子模块的聚集器或依赖项的聚集器.在这种情况下,在第二种情况下使用pom类型来打包ai.h2o:h2o-genmodel的依赖项.为此,您可以检查您的Maven本地存储库(最有可能在$ {user.home}/.m2/repository/ai/h2o/h2o-genmodel/3.18.0.11中,没有jar文件,只有.pom.请阅读此文档依赖机制简介 POM关系

More details why this solution works:
First, the ai.h2o:h2o-genmodel dependency is declared as type pom is because this is how it is published. A maven artefact of type pom is used in two cases: as an aggregator for submodules or as an aggregator for dependencies. In this case, the pom type is used in second scenario, to pack dependencies for ai.h2o:h2o-genmodel. To varify this, you can check your maven local repository (most likely at ${user.home}/.m2/repository/ai/h2o/h2o-genmodel/3.18.0.11 there is no jar file, only the .pom. Please read this documentation Introduction to the Dependency Mechanism and POM Relationships

另一个问题可能是ai.h2o:h2o-genmodel不遵循推荐的包装依赖项的方式,因为它不使用<dependencyManagement>,而是使用了<dependencies>.因此,Maven文档上的详细信息无法完全按预期工作.为了克服这个问题,您必须在<dependencies>上显式使用ai.h2o:h2o-genmodel并手动调整其背后每个依赖项的范围.我强烈建议运行mvn dependency:tree,因为它将显示每个依赖项的范围.在我的输出中,我删除了范围,因为我不希望它污染答案.

Another issue, might be the fact that ai.h2o:h2o-genmodel doesn't adhere to recommended way to wrap dependencies because it doesn't use <dependencyManagement>, but instead is using <dependencies>. Because of this, the details on maven documentation is not working exactly as expected. To overcome this, you have to use ai.h2o:h2o-genmodel explicitly on <dependencies> and adjust manually the scope of each dependency behind it. I strongly suggest to run the mvn dependency:tree because will display the scope of each dependency. In my output I removed the scopes because I didn't want it to polute the answer.

总而言之,为什么在我的解决方案中,声明为pom而在@ kag0中声明的依赖项不为pom是因为ai.h2o:h2o-genmodel是pom类型,而maven对待它的方式相同,因为<type>丢失时会推断出它它来自人工制品pom.

In conclusion, why in my solution works with dependency declared as pom and in @kag0 not as pom is because the ai.h2o:h2o-genmodel is of type pom and maven treat it in same way becaue when the <type> is missing it infers it from the artefact pom.

这篇关于H2O.ai h2o-genmodel.jar包含sl4j绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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