奇怪的 log4j 错误
尝试使用log4j的内置JMSAppender将消息记录到本地消息队列(ActiveMQ)。
我设置了一个测试 Driver
,它有一个入口 main
方法,并且仅实例化我想要建立连接的实际类:
Driver.java
:
public static void main(String[] args) {
Log4jAmqBridge bridge = new Log4jAmqBridge();
bridge.run();
}
Log4jAmqBridge.java
:
public void run() {
// ...
}
如果我将 run
方法完全留空(没有说明)并运行 Driver
,我只会得到一个空控制台(蚀)。但是第二次我将以下构造函数添加到 run()
中:
JMSAppender appender = new JMSAppender();
我收到以下错误:
Exception in thread "main" java.lang.NoClassDefFoundError: javax/jms/JMSException
at test.jmsappender.Log4jAmqBridge.run(Log4jAmqBridge.java:11)
at test.Driver.main(Driver.java:11)
Caused by: java.lang.ClassNotFoundException: javax.jms.JMSException
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 2 more
我检查了 javadoc 并且看起来 JMSAppender
无参数构造函数不会引发异常。
有人知道发生了什么事吗?
编辑: 我实际上使用 Maven 来管理我的依赖项,并在我的 pom 中包含以下依赖项声明:
<dependency>
<scope>compile</scope>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.4</version>
</dependency>
<dependency>
<scope>compile</scope>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.6.4</version>
</dependency>
它将以下 jar 文件放在我的项目中的 Maven 依赖项下(也添加到 Eclipse 工作台类路径中):
- slf4j-api-1.6。 4
- slf4j-log4j12-1.6.4
- log4j-1.2.16
提前致谢!
Trying to use log4j's built-in JMSAppender to log messages to a local message queue (ActiveMQ).
I set up a test Driver
that has an entry main
method and that just instantiates the actual class I want to make the connection:
Driver.java
:
public static void main(String[] args) {
Log4jAmqBridge bridge = new Log4jAmqBridge();
bridge.run();
}
Log4jAmqBridge.java
:
public void run() {
// ...
}
If I leave my run
method totally empty (no instructions) and run the Driver
, I just get an empty console (Eclipse). But the second I add the following constructor to run()
:
JMSAppender appender = new JMSAppender();
I get the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: javax/jms/JMSException
at test.jmsappender.Log4jAmqBridge.run(Log4jAmqBridge.java:11)
at test.Driver.main(Driver.java:11)
Caused by: java.lang.ClassNotFoundException: javax.jms.JMSException
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 2 more
I checked the javadoc and it doesn't look like the JMSAppender
no-arg constructor throws an exception.
Does anybody know whats going on?
Edit:
I am actually using Maven to manage my dependencies and have included the following dependency declarations in my pom:
<dependency>
<scope>compile</scope>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.4</version>
</dependency>
<dependency>
<scope>compile</scope>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.6.4</version>
</dependency>
Which puts the following jars under the Maven Dependencies in my project (which are also added to the Eclipse workbench classpath):
- slf4j-api-1.6.4
- slf4j-log4j12-1.6.4
- log4j-1.2.16
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Log4jAmqBridge 依赖于 JMS API。
将此依赖项添加到您的 pom.xml :
它应该可以解决您的问题。
Log4jAmqBridge depends on the JMS API.
Add this dependency to your pom.xml :
It should solve your problem.