HornetQ - java.lang.NoClassDefFoundError:Lorg / hornetq / core / logging / Logger;

时间:2017-07-19 11:41:59

标签: java jar jms hornetq

我正在尝试从一本书(HornetQ Messaging Developers Guide)中运行一个简单的HornetQ示例,但会收到错误消息。我没有使用过maven,因为我想要贴近书中给出的例子。 HornetQ Standalone服务器通常在命令行启动。我只是想向HonretQ服务器发送消息。

package chapter01;

import javax.jms.JMSException;
import javax.naming.NamingException;

public class ECGMessageConsumerProducerExample {

    public static void main(String[] args) throws NamingException, JMSException {
        // TODO Auto-generated method stub


         javax.naming.Context ic = null;
         javax.jms.ConnectionFactory cf = null;
         javax.jms.Connection connection = null;
         javax.jms.Queue queue = null;
         javax.jms.Session session = null;
         com.mongodb.Mongo m;
         com.mongodb.DB db;
         String destinationName = "queue/DLQ";


         java.util.Properties p = new java.util.Properties();
         p.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY,
         "org.jnp.interfaces.NamingContextFactory");
         p.put(javax.naming.Context.URL_PKG_PREFIXES,
         "org.jboss.naming:org.jnp.interfaces");
         p.put(javax.naming.Context.PROVIDER_URL, "jnp://localhost:1099");
         ic = new javax.naming.InitialContext(p);


         cf = (javax.jms.ConnectionFactory)ic.lookup("/ConnectionFactory");
         queue = (javax.jms.Queue)ic.lookup(destinationName);
         connection = cf.createConnection();
         session = connection.createSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE);
         connection.start();


         String theECG = "1;02/20/2012 14:01:59.010;1020,1021,1022";
         javax.jms.MessageProducer publisher = session.createProducer(queue);
         javax.jms.TextMessage message =
         session.createTextMessage(theECG);
         publisher.send(message);
         System.out.println("Message sent!");
         publisher.close();





    }

}

尽管我添加了书中提到的所有罐子,但我得到以下错误:

Exception in thread "main" java.lang.NoClassDefFoundError: Lorg/hornetq/core/logging/Logger;
    at java.lang.Class.getDeclaredFields0(Native Method)
    at java.lang.Class.privateGetDeclaredFields(Unknown Source)
    at java.lang.Class.getDeclaredField(Unknown Source)
    at java.io.ObjectStreamClass.getDeclaredSUID(Unknown Source)
    at java.io.ObjectStreamClass.access$700(Unknown Source)
    at java.io.ObjectStreamClass$2.run(Unknown Source)
    at java.io.ObjectStreamClass$2.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.io.ObjectStreamClass.<init>(Unknown Source)
    at java.io.ObjectStreamClass.lookup(Unknown Source)
    at java.io.ObjectStreamClass.initNonProxy(Unknown Source)
    at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source)
    at java.io.ObjectInputStream.readClassDesc(Unknown Source)
    at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source)
    at java.io.ObjectInputStream.readClassDesc(Unknown Source)
    at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
    at java.io.ObjectInputStream.readObject0(Unknown Source)
    at java.io.ObjectInputStream.readObject(Unknown Source)
    at org.hornetq.jms.referenceable.SerializableObjectRefAddr.deserialize(SerializableObjectRefAddr.java:79)
    at org.hornetq.jms.referenceable.ConnectionFactoryObjectFactory.getObjectInstance(ConnectionFactoryObjectFactory.java:43)
    at javax.naming.spi.NamingManager.getObjectInstance(Unknown Source)
    at org.jnp.interfaces.NamingContext.getObjectInstance(NamingContext.java:1479)
    at org.jnp.interfaces.NamingContext.getObjectInstanceWrapFailure(NamingContext.java:1496)
    at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:822)
    at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:686)
    at javax.naming.InitialContext.lookup(Unknown Source)
    at chapter01.ECGMessageConsumerProducerExample.main(ECGMessageConsumerProducerExample.java:31)
Caused by: java.lang.ClassNotFoundException: org.hornetq.core.logging.Logger
    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)
    ... 27 more

我还添加了一些我发现与此主题相关的其他罐子,但没有解决问题。

Overview of Jars

错误产生的原因是否存在?

1 个答案:

答案 0 :(得分:1)

你需要hornetq-core jar,下载并使用它