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!
Log4jAmqBridge depends on the JMS API.
Add this dependency to your pom.xml :
It should solve your problem.