- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 python 中使用 storm。我使用这个命令在本地运行拓扑
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
的一部分
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
启动程序。
已找到 slf4 api,否则错误消息将是 ClassNotFoundError
。
问题是log4j要调用下面的方法:
void log(Marker marker, String fqcn, int level, String message, Object[] argArray, Throwable t)
它在 1.7.5 版的 slf4j api 中定义(根据 Javadocs,它自 1.3 版以来就在那里)。
此错误的唯一解释是您的类路径中必须有另一个版本的 slf4j-api.jar,它还没有此方法,并且在加载 LocationAwareLogger 接口(interface)时使用。
请检查
的输出mvn dependency:tree
对于其他出现的 slf4j-api,可能隐藏在树中的某个地方。
另一种查找类加载位置的方法是使用以下代码 (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 依赖 hell )。你能展示你项目的完整 pom.xml
吗?它是否有父 pom 或以其他方式引入的依赖项?如果您明确添加对所需版本的 slf4j-api 的依赖,会发生什么情况:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.9</version>
</dependency>
更新:
问题出在exec-maven-plugin,这是在加载旧版本的slf4j-api。当您从插件的配置中删除以下行时:
<includePluginDependencies>true</includePluginDependencies>
然后加载实际的 slf4j-api。您也可以将该值设置为 false,但无论如何这是默认值。我认为您不需要包含插件依赖项,在构建项目包时您也没有它们。此参数的文档说明:
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 将解决您的问题。
关于java - NoSuchMethodError : org. slf4j,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44091042/
我是一名优秀的程序员,十分优秀!