SLF4J:无法加载类" org.slf4j.impl.StaticLoggerBinder" IntelliJ问题

时间:2018-03-11 05:37:37

标签: java maven intellij-idea

我在IntelliJ程序中收到此错误: SLF4J:无法加载类" org.slf4j.impl.StaticLoggerBinder"。 SLF4J:默认为无操作(NOP)记录器实现 SLF4J:有关详细信息,请参阅http://www.slf4j.org/codes.html#StaticLoggerBinder。 特写:喊叫

从研究来看,我看起来缺少JAR文件,更新类路径等。 一些答案说要在Maven POM中添加依赖关系,所以我已经完成了这个,点击" build"并重新使用具有相同结果的功能文件。 一些答案也说添加jar文件,但我真的不熟悉Java IDE而不是开发人员。我已经用Google搜索了如何添加jar文件,大多数答案都告诉我转到IntelliJ中的Project结构。在Project Structure的工件部分,我点击了#34; +"我看到一个从模块创建jar的选项,但这个弹出窗口真的很混乱。我不明白我应该怎么做。我还下载了SLF4J jar文件,但我不知道如何在IntellJ中获取它们。从模块创建JAR似乎没有指向桌面的链接以导入任何内容。从空创建jar导致另一个屏幕看起来没有任何链接到桌面。其他结果表示从模块下的+符号添加一个jar文件,这似乎也没有提供任何选项。我也不确定这有多大问题,因为运行我的功能文件会导致输出错误,并且可能无论此问题如何。

这是我的POM,然后:

     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>



<groupId>cucumber-school</groupId>

<artifactId>shouty</artifactId>

<version>0.0.1</version>

<packaging>jar</packaging>

<name>Shouty</name>



<properties>
    <java.version>1.8</java.version>
    <junit.version>4.12</junit.version>

    <cucumber.version>2.3.1</cucumber.version>

    <cucumber.pro.version>2.0.4</cucumber.pro.version>

    <maven.compiler.version>3.3</maven.compiler.version>

</properties>



<dependencies>

    <dependency>

        <groupId>io.cucumber</groupId>

        <artifactId>cucumber-java</artifactId>

        <version>${cucumber.version}</version>

        <scope>test</scope>

    </dependency>



    <dependency>

        <groupId>io.cucumber</groupId>

        <artifactId>cucumber-junit</artifactId>

        <version>${cucumber.version}</version>

        <scope>test</scope>

    </dependency>



    <dependency>

        <groupId>io.cucumber</groupId>

        <artifactId>pro-plugin</artifactId>

        <version>${cucumber.pro.version}</version>

        <scope>test</scope>

    </dependency>



    <dependency>

        <groupId>junit</groupId>

        <artifactId>junit</artifactId>

        <version>${junit.version}</version>

        <scope>test</scope>

    </dependency>

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.5</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>1.7.5</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-simple</artifactId>
        <version>1.7.21</version>
    </dependency>

</dependencies>

4 个答案:

答案 0 :(得分:9)

在这里添加这个,希望它能帮助其他地方的其他人。我在Mac上使用IntelliJ。最初,我得到了#34;无法加载类org.slf4j.impl.StaticLoggerBinder消息&#34;所以我添加了以下依赖项:

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.8.0-beta2</version>
    </dependency>

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-simple</artifactId>
        <version>1.8.0-beta2</version>
        <scope>test</scope>
    </dependency>

请注意,版本应更改为每个版本所需的版本。在此之后,我开始获得&#34;没有找到SLF4J提供商&#34;错误信息。我不得不去File - &gt;项目结构 - &gt;模块 - &gt;依赖选项卡 - &gt;选择两个依赖项 - &gt;确保他们的范围是&#34;编译&#34;不是&#34;测试&#34; - &GT;点击&#34;应用&#34; - &GT;点击&#34;确定&#34;。enter image description here

答案 1 :(得分:1)

当我尝试使用Maven构建项目Scala 2.11时,我遇到了同样的问题,但是添加依赖关系的解决方案没有帮助。 从项目结构->模块->依赖关系中删除scala.sdk.2.11.12解决了我的问题。

答案 2 :(得分:0)

如果发现它难以找到POM.xml,请尝试检查IntelliJ IDE的可用更新,然后尝试更新它。在更新过程中,新版本的IntelliJ将显示需要修复的问题(包括缺少的jar文件或类路径冲突)。

答案 3 :(得分:-1)

类路径中应该有log4j.properties/xml或logback.properties/xml。将其保存在已在类路径中的文件夹中或明确提及新条目。我遇到了同样的问题,当我在我的src / main / resources中放入logback.properties时,它已经解决了

在我的情况下也尝试使用这些组合我添加了这些依赖项

   <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>jcl-over-slf4j</artifactId>
        <version>1.7.0</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.0</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>1.7.0</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.14</version>
    </dependency>
相关问题