NoSuchMethodError:org.slf4j [英] NoSuchMethodError: org.slf4j

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

问题描述

我正在使用python风暴.我使用此命令在本地运行拓扑

I'm using storm with python. I used this command to run the topology locally

mvn compile exec:java -Dexec.classpathScope=compile -Dexec.mainClass=my.Topology

并收到此错误

java.lang.NoSuchMethodError: org.slf4j.spi.LocationAwareLogger.log(Lorg/slf4j/Marker;Ljava/lang/String;ILjava/lang/String;[Ljava/lang/Object;Ljava/lang/Throwable;)V
at org.apache.log4j.Category.differentiatedLog(Category.java:186)
at org.apache.log4j.Category.info(Category.java:229)

我使用此命令mvn dependency:tree来查看slf4j的版本 这是我得到的slf4j的一部分

I used this command mvn dependency:tree to see the versions of slf4j and here is the part of slf4j i got

org.apache.storm:storm-core:jar:0.9.6:provided
[INFO]    +- org.clojure:clojure:jar:1.5.1:provided
[INFO]    +- clj-time:clj-time:jar:0.4.1:provided
[INFO]    +- joda-time:joda-time:jar:2.0:provided
[INFO]    +- compojure:compojure:jar:1.1.3:provided
[INFO]    +- org.clojure:core.incubator:jar:0.1.0:provided
[INFO]    +- org.clojure:tools.macro:jar:0.1.0:provided
[INFO]    +- clout:clout:jar:1.0.1:provided
[INFO]    +- ring:ring-core:jar:1.1.5:provided
[INFO]    +- commons-fileupload:commons-fileupload:jar:1.2.1:provided
[INFO]    +- javax.servlet:servlet-api:jar:2.5:provided
[INFO]    +- hiccup:hiccup:jar:0.3.6:provided
[INFO]    +- ring:ring-devel:jar:0.3.11:provided
[INFO]    +- clj-stacktrace:clj-stacktrace:jar:0.2.2:provided
[INFO]    +- ring:ring-jetty-adapter:jar:0.3.11:provided
[INFO]    +- ring:ring-servlet:jar:0.3.11:provided
[INFO]    +- org.mortbay.jetty:jetty:jar:6.1.26:provided
[INFO]    +- org.mortbay.jetty:jetty-util:jar:6.1.26:provided
[INFO]    +- org.clojure:tools.logging:jar:0.2.3:provided
[INFO]    +- org.clojure:math.numeric-tower:jar:0.0.1:provided
[INFO]    +- org.clojure:tools.cli:jar:0.2.4:provided
[INFO]    +- commons-io:commons-io:jar:2.4:provided
[INFO]    +- org.apache.commons:commons-exec:jar:1.1:provided
[INFO]    +- commons-lang:commons-lang:jar:2.5:provided
[INFO]    +- com.googlecode.json-simple:json-simple:jar:1.1:provided
[INFO]    +- com.twitter:carbonite:jar:1.4.0:provided
[INFO]    +- com.esotericsoftware.kryo:kryo:jar:2.21:provided
[INFO]    +- 
  com.esotericsoftware.reflectasm:reflectasm:jar:shaded:1.07:provided
[INFO]    +- org.ow2.asm:asm:jar:4.0:provided
[INFO]    +- com.esotericsoftware.minlog:minlog:jar:1.2:provided
[INFO]    +- org.objenesis:objenesis:jar:1.2:provided
[INFO]    +- com.twitter:chill-java:jar:0.3.5:provided
[INFO]    +- org.yaml:snakeyaml:jar:1.11:provided
[INFO]    +- commons-logging:commons-logging:jar:1.1.3:provided
[INFO]    +- commons-codec:commons-codec:jar:1.6:provided
[INFO]    +- com.googlecode.disruptor:disruptor:jar:2.10.4:provided
[INFO]    +- org.jgrapht:jgrapht-core:jar:0.9.0:provided
[INFO]    +- ch.qos.logback:logback-classic:jar:1.0.13:provided
[INFO]    +- ch.qos.logback:logback-core:jar:1.0.13:provided
[INFO]    +- org.slf4j:slf4j-api:jar:1.7.5:provided
[INFO]    +- org.slf4j:log4j-over-slf4j:jar:1.6.6:provided
[INFO]    \- jline:jline:jar:2.11:provided

我的POM

<project xmlns="http://maven.apache.org/POM/4.0.0" 
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>Sim</groupId>
<artifactId>Project</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>Pro</name>
<url>http://maven.apache.org</url>
<dependencies>
  <dependency>
    <groupId>org.apache.storm</groupId>
    <artifactId>storm-core</artifactId>
    <version>0.9.6</version>
    <scope>provided</scope>
  </dependency>
  </dependencies>
  <build>
    <resources>
      <resource>
        <directory> ${basedir}/multilang</directory>
      </resource>
    </resources>
<plugins>
 <plugin>
  <artifactId>maven-assembly-plugin</artifactId>
   <configuration>
     <descriptorRefs>
        <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
                </configuration>
            <executions>
                <execution>
                    <id>make-assembly</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
             <groupId>org.codehaus.mojo</groupId>
             <artifactId>exec-maven-plugin</artifactId>
             <version>1.5.0</version>
             <executions>
                 <execution>
                     <goals>
                        <goal>exec</goal>
                     </goals>
                 </execution>
             </executions>
            <configuration>
                <executable>java</executable>
  <includeProjectDependencies>true</includeProjectDependencies>
  <includePluginDependencies>true</includePluginDependencies>
  <classpathScope>compile</classpathScope>                                  
  <mainClass>Sim.Topology</mainClass>
                          </configuration>
                    </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
                            <version>2.3</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>
    </plugins>

推荐答案

修改后的答案

我第一次怀疑是一个错误,因为这是您使用classpathScope=compile启动程序的原因,这是提供或编译范围依赖项的问题.

I was wrong with my first suspicion that this is a problem of provided or compile scope dependencies, as you are starting the program with classpathScope=compile.

找到slf4 api,否则错误消息应该是ClassNotFoundError.

The slf4 api is found, otherwise the error message would have been a ClassNotFoundError.

问题在于log4j要调用以下方法:

The problem is that log4j wants to call the following method:

void log(Marker marker, String fqcn, int level, String message, Object[] argArray, Throwable t)

在1.7.5版的slf4j api中定义(根据Javadocs,该版本从1.3版开始存在).

which is defined in the slf4j api in version 1.7.5 (it's in there since version 1.3 according to the Javadocs).

此错误的唯一解释是,您的类路径上必须存在另一个版本的slf4j-api.jar,该版本尚没有此方法,并且在加载LocationAwareLogger接口时会使用该版本.

The only explanation for this error is that there must be another version of slf4j-api.jar on your classpath which does not yet have this method and which is used when loading the LocationAwareLogger interface.

请检查

mvn dependency:tree

对于其他出现的slf4j-api,可能隐藏在树中的某个地方.

for other occurrences of slf4j-api, perhaps hidden somewhere in the tree.

找到类从何处加载的另一种可能性是使用以下代码(

Another possibility to find where the class is loaded from is by using the following code (taking from this question):

    Class clazz = Class.forName("org.slf4j.spi.LocationAwareLogger");
    URL resourceUrl = clazz.getResource("/" + clazz.getCanonicalName().replace(".", "/") + ".class");
    System.out.println(resourceUrl.toString());

更新:

因此,当使用mvn exec运行程序时,会加载1.5.6版的slf4j-api(欢迎使用maven依赖地狱).您可以显示项目的完整pom.xml吗?它是否具有父pom或以其他方式引入的依赖关系?如果通过添加以下内容显式添加对所需版本的slf4j-api的依赖关系,会发生什么情况?

So when running the program with mvn exec there is a slf4j-api loaded with version 1.5.6 (welcome to the maven dependency hell). Can you show the complete pom.xml of your project? Does it have a parent pom or otherwise introduced dependencies? What happens if you explicitly add a dependency on the required version of slf4j-api by adding:

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

更新:

问题来自exec-maven-plugin,它正在加载旧版本的slf4j-api.当您从插件的配置中删除以下行时:

The problem comes from the exec-maven-plugin, this is loading the older version of slf4j-api. When you remove the following line from the configuration of the plugin:

<includePluginDependencies>true</includePluginDependencies>

然后将加载实际的slf4j-api.您也可以将值设置为 false ,但这仍然是默认值.我认为您不需要包含插件依赖项,而在构建项目的程序包时也不需要它们.此参数的文档指出:

then the actual slf4j-api is loaded. You could as well set the value to false, but that's the default value anyway. I do not think that you should need to include the plugin dependencies, when building the package of your project you do not have them either. The documentation for this parameter states:

指示在执行主类时是否应使用此插件的依赖项.当项目依赖项不合适时,这很有用.当项目不是Java项目时,仅使用插件依赖项可能特别有用.例如,使用csharp插件的mvn项目只希望将dotnet库视为依赖项.

Indicates if this plugin's dependencies should be used when executing the main class. This is useful when project dependencies are not appropriate. Using only the plugin dependencies can be particularly useful when the project is not a java project. For example a mvn project using the csharp plugins only expects to see dotnet libraries as dependencies.

因此,我认为删除此行或将值设置为false将解决您的问题.

So I think that removing this line or setting the value to false will solve your problem.

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

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