ActiveMQ Anfänger-Fehler

mhamp

Mitglied
Hallo zusammen!

Ich bin gerade dabei mich etwas in ActiveMQ einzuarbeiten und benutze dazu folgendes Tutorial: JavaBlogging Simple guide to Java Message Service (JMS) using ActiveMQ

ActiveMQ läuft soweit und ich kann die Admin-Konsole über ServerCon erreichen.

In meiner Producer-Klasse (laut Tutorial) bekomme ich allerdings folgende Fehlermeldung:

Code:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/Level
	at org.slf4j.LoggerFactory.getSingleton(LoggerFactory.java:230)
	at org.slf4j.LoggerFactory.bind(LoggerFactory.java:121)
	at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:112)
	at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:275)
	at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:248)
	at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:261)
	at org.apache.activemq.ActiveMQPrefetchPolicy.<clinit>(ActiveMQPrefetchPolicy.java:38)
	at org.apache.activemq.ActiveMQConnectionFactory.<init>(ActiveMQConnectionFactory.java:88)
	at org.apache.activemq.ActiveMQConnectionFactory.<init>(ActiveMQConnectionFactory.java:131)
	at Producer.main(Producer.java:21)
Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Level
	at java.net.URLClassLoader$1.run(Unknown Source)
	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)
	... 10 more

Meine Producer-Klasse sieht folgendermaßen aus:
Java:
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;

import org.apache.activemq.ActiveMQConnection;
import org.apache.activemq.ActiveMQConnectionFactory;



public class Producer {

	private static String	url		= ActiveMQConnection.DEFAULT_BROKER_URL;
	private static String	subject	= "TESTQUEUE";


	public static void main( String[] args ) {
		ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(
				url );

		try {
			Connection connection = connectionFactory.createConnection();

			connection.start();

			Session session = connection.createSession( false,
					Session.AUTO_ACKNOWLEDGE );

			Destination destination = session.createQueue( subject );

			MessageProducer messageProducer = session
					.createProducer( destination );

			TextMessage message = session.createTextMessage( "Hallo ActiveMQ!" );

			messageProducer.send( message );
			System.out.println( "Sent message '" + message.getText() + "'" );

			connection.close();

		} catch ( JMSException e ) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}

Laut Fehlermeldung tritt der Fehler ja in dieser Zeile auf:
Java:
ConnectionFactory connectionFactory = new ActiveMQConnectionFactory( url );
 
Du musst log4j mit in den Classpath aufnehmen. Das genaue Verfahren dazu variiert je nachdem welche IDE du nutzt. Aber kurzes Googlen sollte dir helfen.
 
Ich benutze Eclipse. Log4J habe ich ebenfalls eingebunden (siehe Screenshot). Fehlt noch eine andere Bibliothek?
 

Anhänge

  • log4j.png
    log4j.png
    67,9 KB · Aufrufe: 42

Zurück
Oben