ClassNotFoundException when client connects to HornetQ

1.7k views Asked by At

I'm trying to build a simple JAR that publishes a message to a queue in HornetQ, and run the JAR from Eclipse. I'm getting the following error. I'm guessing it's related to assembly versions, but I'm not sure how to track it down.

javax.naming.NamingException: Failed to lookup [Root exception is java.io.IOException: java.lang.ClassNotFoundException: org.hornetq.core.client.impl.AfterConnectInternalListener]
    at org.jboss.naming.remote.client.ClientUtil.namingException(ClientUtil.java:36)
    at org.jboss.naming.remote.protocol.v1.Protocol$1.execute(Protocol.java:101)
    at org.jboss.naming.remote.protocol.v1.RemoteNamingStoreV1.lookup(RemoteNamingStoreV1.java:76)
    at org.jboss.naming.remote.client.RemoteContext.lookup(RemoteContext.java:77)
    at org.jboss.naming.remote.client.RemoteContext.lookup(RemoteContext.java:81)
    at javax.naming.InitialContext.lookup(Unknown Source)
    at com.me.joel.MessageCreator.createMessage(MessageCreator.java:20)
    at com.me.joel.MessageProducerJar.main(MessageProducerJar.java:9)
Caused by: java.io.IOException: java.lang.ClassNotFoundException: org.hornetq.core.client.impl.AfterConnectInternalListener
    at org.jboss.naming.remote.protocol.v1.Protocol$1$3.read(Protocol.java:156)
    at org.jboss.naming.remote.protocol.v1.BaseProtocolCommand.readResult(BaseProtocolCommand.java:60)
    at org.jboss.naming.remote.protocol.v1.Protocol$1.handleClientMessage(Protocol.java:146)
    at org.jboss.naming.remote.protocol.v1.RemoteNamingStoreV1$MessageReceiver$1.run(RemoteNamingStoreV1.java:184)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.hornetq.core.client.impl.AfterConnectInternalListener
    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)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Unknown Source)
    at org.jboss.marshalling.AbstractClassResolver.loadClass(AbstractClassResolver.java:135)
    at org.jboss.marshalling.AbstractClassResolver.resolveClass(AbstractClassResolver.java:116)
    at org.jboss.marshalling.river.RiverUnmarshaller.doReadClassDescriptor(RiverUnmarshaller.java:870)
    at org.jboss.marshalling.river.RiverUnmarshaller.doReadClassDescriptor(RiverUnmarshaller.java:902)
    at org.jboss.marshalling.river.RiverUnmarshaller.doReadNewObject(RiverUnmarshaller.java:1204)
    at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:272)
    at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:209)
    at org.jboss.marshalling.river.RiverUnmarshaller.readFields(RiverUnmarshaller.java:1677)
    at org.jboss.marshalling.river.RiverUnmarshaller.doInitSerializable(RiverUnmarshaller.java:1593)
    at org.jboss.marshalling.river.RiverUnmarshaller.doInitSerializable(RiverUnmarshaller.java:1557)
    at org.jboss.marshalling.river.RiverUnmarshaller.doReadNewObject(RiverUnmarshaller.java:1235)
    at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:272)
    at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:209)
    at org.jboss.marshalling.AbstractObjectInput.readObject(AbstractObjectInput.java:37)
    at org.jboss.naming.remote.protocol.v1.Protocol$1$3.read(Protocol.java:153)
    ... 6 more

This is my code:

public void createMessage() throws Exception{
        String destinationName = "queue/test";

        Context ic = null;
        ConnectionFactory cf = null;
        Connection connection =  null;

        try {         
            ic = getInitialContext();

            cf = (ConnectionFactory)ic.lookup("jms/RemoteConnectionFactory");
            //Topic topic = (Topic)ic.lookup(destinationName);
            Queue objQueue = (Queue)ic.lookup(destinationName);

            connection = cf.createConnection();
            Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
            MessageProducer publisher = session.createProducer(objQueue);
            //MessageConsumer subscriber = session.createConsumer(topic);

            //subscriber.setMessageListener(this);
            connection.start();

            TextMessage message = session.createTextMessage("Hello!");
            publisher.send(message);

            //Scanner keyIn = new Scanner(System.in);

            //System.out.print("JMS Server listening. Type a Key + CR to exit\n");
            //keyIn.next();

        }
        finally
        {   
            if(ic != null)
            {
                try
                {
                    ic.close();
                }
                catch(Exception e)  {
                    throw e;
                }
            }

            closeConnection(connection);
        }
    }

    public static Context getInitialContext( ) throws javax.naming.NamingException {

        Properties p = new Properties( );
        p.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
        //p.put(Context.URL_PKG_PREFIXES," org.jboss.naming:org.jnp.interfaces");
        p.put(Context.PROVIDER_URL, "remote://localhost:4447");
        p.put(Context.SECURITY_PRINCIPAL, "user");
        p.put(Context.SECURITY_CREDENTIALS, "password");
        return new javax.naming.InitialContext(p);
        //return new javax.naming.InitialContext();
    }  

And my POM dependencies

<dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
   <!--  <dependency>  
       <groupId>org.hornetq</groupId>  
       <artifactId>hornetq-core</artifactId>  
       <version>2.2.6.Final</version>  
       <scope>provided</scope>  
    </dependency>   -->
    <dependency>
        <groupId>org.hornetq</groupId>
        <artifactId>hornetq-core-client</artifactId>
        <version>2.2.6.Final</version>
        <scope>provided</scope>
    </dependency>
    <!-- <dependency>  
       <groupId>org.hornetq</groupId>  
       <artifactId>hornetq-jms</artifactId>  
       <version>2.2.18.Final</version>  
       <scope>provided</scope>  
    </dependency> -->  
    <dependency>
        <groupId>org.hornetq</groupId>
        <artifactId>hornetq-jms-client</artifactId>
        <version>2.2.18.Final</version>
    </dependency>
    <dependency>
        <groupId>org.hornetq</groupId>
        <artifactId>hornetq-jms-client</artifactId>
        <version>2.2.6.Final</version>
        <scope>provided</scope>
    </dependency>
    <!-- <dependency>  
       <groupId>org.hornetq</groupId>  
       <artifactId>hornetq-logging</artifactId>  
       <version>2.2.6.Final</version>  
       <scope>provided</scope>  
    </dependency>  --> 
    <dependency>
        <groupId>org.hornetq.rest</groupId>
        <artifactId>hornetq-rest</artifactId>
        <version>2.2.2.Final</version>
    </dependency>
    <!-- <dependency>  
       <groupId>org.hornetq</groupId>  
       <artifactId>hornetq-transports</artifactId>  
       <version>2.1.0</version>  
       <scope>compile</scope>  
    </dependency>   -->
<!--    <dependency>  
       <groupId>org.jboss.netty</groupId>  
       <artifactId>netty</artifactId>  
       <version>3.1.0.GA</version>  
    </dependency>   -->
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.16</version>
        <exclusions>
            <exclusion>
                <groupId>javax.mail</groupId>
                <artifactId>mail</artifactId>
            </exclusion>
            <exclusion>
                <groupId>javax.jms</groupId>
                <artifactId>jms</artifactId>
            </exclusion>
            <exclusion>
                <groupId>com.sun.jdmk</groupId>
                <artifactId>jmxtools</artifactId>
            </exclusion>
            <exclusion>
                <groupId>com.sun.jmx</groupId>
                <artifactId>jmxri</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>  
       <groupId>org.jboss.javaee</groupId>  
       <artifactId>jboss-jms-api</artifactId>  
       <version>1.1.0.GA</version>  
       <scope>compile</scope>  
    </dependency>  

    <dependency>
        <groupId>org.jboss.as</groupId>
        <artifactId>jboss-as-ejb-client-bom</artifactId>
        <version>7.1.0.Final</version>
        <type>pom</type>
        <scope>compile</scope>
    </dependency>
    <!-- 
  <dependency>  
     <groupId>org.hornetq</groupId>  
     <artifactId>hornetq-core</artifactId>  
     <version>2.0.0.GA</version>  
     <scope>compile</scope>  
  </dependency> 
    <dependency>  
   <groupId>org.hornetq</groupId>  
   <artifactId>hornetq-core-client</artifactId>  
   <version>2.0.0.GA</version>  
   <scope>compile</scope>  
</dependency>  
  <dependency>  
     <groupId>org.hornetq</groupId>  
     <artifactId>hornetq-jms</artifactId>  
     <version>2.0.0.GA</version>  
     <scope>compile</scope>  
  </dependency>  
<dependency>  
   <groupId>org.hornetq</groupId>  
   <artifactId>hornetq-jms-client</artifactId>  
   <version>2.0.0.GA</version>  
   <scope>compile</scope>  
</dependency>  
<dependency>  
   <groupId>org.hornetq</groupId>  
   <artifactId>hornetq-transports</artifactId>  
   <version>2.0.0.GA</version>  
   <scope>compile</scope>  
</dependency>  
<dependency>  
   <groupId>org.jboss.netty</groupId>  
   <artifactId>netty</artifactId>  
   <version>3.1.0.GA</version>  
</dependency>   -->
<dependency>  
   <groupId>org.jboss.javaee</groupId>  
   <artifactId>jboss-jms-api</artifactId>  
   <version>1.1.0.GA</version>  
   <scope>compile</scope>  
</dependency>  
  </dependencies>
1

There are 1 answers

5
A.v On

You just mentioned that the hornetq-core-client lib is provided:

<dependency>
    <groupId>org.hornetq</groupId>
    <artifactId>hornetq-core-client</artifactId>
    <version>2.2.6.Final</version>
    <scope>provided</scope>
</dependency>

Which obviously is not and because of that you get ClassNotFoundException on org.hornetq.core.client.impl.AfterConnectInternalListener.