使用 log4j 的多个库
我正在编写一个小型 Java 应用程序,并且在使用 log4j 时遇到了一些问题,这似乎是由多个独立库试图同时使用它引起的:
Exception in thread "main" java.lang.NoSuchMethodError: org.apache.log4j.Logger.info(Ljava/lang/String;)V
at twitter4j.internal.logging.Log4JLogger.info(Log4JLogger.java:85)
at twitter4j.internal.logging.Logger.<clinit>(Logger.java:72)
at twitter4j.http.BasicAuthorization.<clinit>(BasicAuthorization.java:43)
at twitter4j.http.AuthorizationFactory.getBasicAuthorizationInstance(AuthorizationFactory.java:66)
at twitter4j.TwitterStreamFactory.getInstance(TwitterStreamFactory.java:121)
at org.voltdb.twitter.drivers.Collect.main(Collect.java:13)
我正在使用的两个库是 Twitter4J 和 VoltDB。两者都是 JAR 的形式。如果我单独使用其中任何一个,我都不会遇到这个问题;两者都可以单独工作。
如果这可以解决问题,则禁用任一库的 log4j 组件是可以接受的。
I'm writing a small Java application and having some trouble with log4j that appears to be caused by multiple, independent libraries trying to use it simultaneously:
Exception in thread "main" java.lang.NoSuchMethodError: org.apache.log4j.Logger.info(Ljava/lang/String;)V
at twitter4j.internal.logging.Log4JLogger.info(Log4JLogger.java:85)
at twitter4j.internal.logging.Logger.<clinit>(Logger.java:72)
at twitter4j.http.BasicAuthorization.<clinit>(BasicAuthorization.java:43)
at twitter4j.http.AuthorizationFactory.getBasicAuthorizationInstance(AuthorizationFactory.java:66)
at twitter4j.TwitterStreamFactory.getInstance(TwitterStreamFactory.java:121)
at org.voltdb.twitter.drivers.Collect.main(Collect.java:13)
The two libraries I'm using are Twitter4J and VoltDB. Both are in the form of JARs. If I use either in isolation, I don't run into this problem; both work fine on their own.
It would be acceptable to disable the log4j component of either library if this fixed the problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您确定您使用的是两个库所需的正确版本的 log4j 吗?您的错误消息似乎表明 log4j 版本不正确。
Are you sure you're using the right version of log4j as required by both libraries? Your error message seems to indicate in incorrect log4j version IMO.
我遇到了对 Twitter4J 日志记录问题的回复,其中显示了如何禁用日志记录:
添加此属性使异常消失。
I came across a reply to a Twitter4J logging problem that shows how to disable logging:
Adding this property made the exception disappear.