3 Replies Latest reply on Jul 20, 2017 2:31 PM by Justin Bertram

    HornetQ: producer consumer example:  NoClassDefFoundError

    Julian Hebold Newbie

      I am trying to run a simple HornetQ example from a book (HornetQ Messaging Developers Guide) but get error messages.

      I have not used maven since I wanted to stick close to the example given in the book. The HornetQ Standalone server started normally in command line.

      I am just trying to send a message to the HonretQ server. I used the jar.files mentioned in the hornetq documentaion: (hornet-core-client, hornetq-jms-client, netty, jnp-client, jboss-jms)




      package senderReceiver;



      import javax.jms.JMSException;

      import javax.naming.NamingException;



      public class Client {



      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.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);











      Nontheless I get the following error:


      Exception in thread "main" java.lang.NoClassDefFoundError: org/hornetq/api/core/HornetQException

      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.readOrdinaryObject(Unknown Source)

      at java.io.ObjectInputStream.readObject0(Unknown Source)

      at java.io.ObjectInputStream.defaultReadFields(Unknown Source)

      at java.io.ObjectInputStream.readSerialData(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:78)

      at org.hornetq.jms.referenceable.ConnectionFactoryObjectFactory.getObjectInstance(ConnectionFactoryObjectFactory.java:42)

      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 senderReceiver.Client.main(Client.java:33)

      Caused by: java.lang.ClassNotFoundException: org.hornetq.api.core.HornetQException

      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)

      ... 29 more





      I really do not know why, since I followed the example in the book and the instructions of the manual. What can cause the error?

        • 1. Re: HornetQ: producer consumer example:  NoClassDefFoundError
          Justin Bertram Master

          The book you're using (i.e. HornetQ Messaging Developer’s Guide) was published way back in 2012 (around 5 years ago now).  A lot of changes have occurred since then.  A couple of years ago the HornetQ code-base was donated to the Apache ActiveMQ community, and it is now being developed as the ActiveMQ Artemis broker.  HornetQ itself is no longer under active development (and hasn't been for the last couple of years).  I recommend you move from whatever version of HornetQ you're looking at and use ActiveMQ Artemis instead.


          The NoClassDefFoundError you're getting simply looks like you haven't included all the proper jar files on your classpath.  You don't say which version of HornetQ you're using so I can't provide a specific recommendation on what jar file(s) to include.  In any event, HornetQ (and Artemis) ships with numerous examples which are simple to run and modify.  The examples are Maven based so maybe that's why you're not using them.


          FWIW, I've been working in the HornetQ/Artemis code-base since it was first released and I don't recall ever seeing the book's author (Piero Giacomelli) contribute any code or ask/answer any questions on the related forums or mailing lists.

          • 2. Re: HornetQ: producer consumer example:  NoClassDefFoundError
            Julian Hebold Newbie

            Thanks for the input ! I was using hornetq-2.4.0.Final version. In general I need to implement a pub/sub middleware. So my choice was a lightweight JMS Service.

            I liked the idea of HonretQ since I can run the service within a standalone server. I am going to have a look at Artemis. Since I am a Neewbie It is important for me to have

            detailed instructions for setting up a JMS service, otherwise I quickly feel lost. I hope the newer solution is suitable for me.


            Best regards.

            • 3. Re: HornetQ: producer consumer example:  NoClassDefFoundError
              Justin Bertram Master

              ActiveMQ Artemis is a lightweight messaging service that supports pub/sub semantics.  It has all the power of HornetQ plus a lot of other functionality and protocol support that has been added in the last 2 years or so.  You can find instructions on how to create your broker instance and start/stop it in the documentation.


              If you have additional questions please feel free to use the ActiveMQ User List.