1 2 3 Previous Next 32 Replies Latest reply on Nov 11, 2005 2:13 AM by matrix1234 Go to original post
      • 15. Re: JMS problem
        darranl

        java.lang.ClassNotFoundException

        The class named in the exception can not be found.

        Try using jbossall-client.jar instead of the j2ee.jar you are currently using.

        • 16. Re: JMS problem
          matrix1234

          Not working yet...

          here is the report

          java -classpath .;e:\j2ee.jar;c:\jboss\client\jbossall-client.jar
           QueueSend
          javax.naming.NameNotFoundException: JmsQueueConnectionFactory not bound
           at org.jnp.server.NamingServer.getBinding(NamingServer.java:491)
           at org.jnp.server.NamingServer.getBinding(NamingServer.java:499)
           at org.jnp.server.NamingServer.getObject(NamingServer.java:505)
           at org.jnp.server.NamingServer.lookup(NamingServer.java:278)
           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
           at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
          java:39)
           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
          sorImpl.java:25)
           at java.lang.reflect.Method.invoke(Method.java:324)
           at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:261)
           at sun.rmi.transport.Transport$1.run(Transport.java:148)
           at java.security.AccessController.doPrivileged(Native Method)
           at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
           at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:4
          60)
           at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport
          .java:701)
           at java.lang.Thread.run(Thread.java:534)
           at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Unknow
          n Source)
           at sun.rmi.transport.StreamRemoteCall.executeCall(Unknown Source)
           at sun.rmi.server.UnicastRef.invoke(Unknown Source)
           at org.jnp.server.NamingServer_Stub.lookup(Unknown Source)
           at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:610)
           at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:572)
           at javax.naming.InitialContext.lookup(Unknown Source)
           at QueueSend.main(QueueSend.java:30)
          
          



          • 17. Re: JMS problem
            matrix1234

            whats happening ?

            • 18. Re: JMS problem
              peterj

              The line of code that reads as follows:

              QueueConnectionFactory queueConnectionFactory =
              (QueueConnectionFactory)context.lookup("JmsQueueConnectionFactory");


              should read:
              QueueConnectionFactory queueConnectionFactory =
              (QueueConnectionFactory)context.lookup("ConnectionFactory");


              At least that's what works on my JMS app.

              • 19. Re: JMS problem
                matrix1234

                still not working !!
                here is the report

                
                java -classpath .;e:\j2ee.jar;c:\jboss\client\jbossall-client.jar
                QueueSend
                javax.naming.NameNotFoundException: queue1 not bound
                 at org.jnp.server.NamingServer.getBinding(NamingServer.java:491)
                 at org.jnp.server.NamingServer.getBinding(NamingServer.java:499)
                 at org.jnp.server.NamingServer.getObject(NamingServer.java:505)
                 at org.jnp.server.NamingServer.lookup(NamingServer.java:278)
                 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
                java:39)
                 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
                sorImpl.java:25)
                 at java.lang.reflect.Method.invoke(Method.java:324)
                 at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:261)
                 at sun.rmi.transport.Transport$1.run(Transport.java:148)
                 at java.security.AccessController.doPrivileged(Native Method)
                 at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
                 at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:4
                60)
                 at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport
                .java:701)
                 at java.lang.Thread.run(Thread.java:534)
                 at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Unknow
                n Source)
                 at sun.rmi.transport.StreamRemoteCall.executeCall(Unknown Source)
                 at sun.rmi.server.UnicastRef.invoke(Unknown Source)
                 at org.jnp.server.NamingServer_Stub.lookup(Unknown Source)
                 at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:610)
                 at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:572)
                 at javax.naming.InitialContext.lookup(Unknown Source)
                 at QueueSend.main(QueueSend.java:39)
                


                and here is the latest code
                import java.util.Hashtable;
                
                import javax.jms.JMSException;
                import javax.jms.Queue;
                import javax.jms.QueueConnection;
                import javax.jms.QueueConnectionFactory;
                import javax.jms.QueueSender;
                import javax.jms.QueueSession;
                import javax.jms.Session;
                import javax.jms.TextMessage;
                import javax.naming.Context;
                import javax.naming.InitialContext;
                import javax.naming.NamingException;
                
                public class QueueSend
                {
                 public static void main(String[] args)
                 {
                 try
                 {
                 // create a JNDI context
                 Hashtable env = new Hashtable();
                 env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
                 env.put(Context.PROVIDER_URL, "jnp://localhost:1099");
                 env.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
                 Context context = new InitialContext(env);
                
                
                 // retrieve queue connection factory
                 QueueConnectionFactory queueConnectionFactory = (QueueConnectionFactory)context.lookup("ConnectionFactory");
                 // create a queue connection
                 QueueConnection queueConnection = queueConnectionFactory.createQueueConnection();
                
                 // create a queue session
                 // set transactions to false and set auto acknowledgement of receipt of messages
                 QueueSession queueSession = queueConnection.createQueueSession(false,Session.AUTO_ACKNOWLEDGE);
                
                 // retrieve queue
                 Queue queue = (Queue)context.lookup("queue1");
                
                 // create a queue sender and associate to the retrieved queue
                 QueueSender queueSender = queueSession.createSender(queue);
                
                 // send a message to the queue
                 TextMessage message = queueSession.createTextMessage();
                 message.setText("Hello there.");
                 queueSender.send(message);
                
                 System.out.println("Sample application writing message to queue.");
                
                 // clean up
                 queueSender.close();
                 queueSession.close();
                 queueConnection.close();
                
                 }
                 catch (NamingException e)
                 {
                 e.printStackTrace();
                 }
                 catch (JMSException e)
                 {
                 e.printStackTrace();
                 }
                
                
                 }
                }
                
                




                whats wrong ?

                • 20. Re: JMS problem
                  matrix1234

                  this code is used for the openJMS server. probabily it has "queue1" as a default.

                  whats the default in Jboss ? i may have have to replace this .

                  whats that ?

                  • 21. Re: JMS problem
                    matrix1234

                    here is the openJMS tutorial claims.....

                    The code for the QueueSend class shown below follows these steps. Note that it uses a queue named queue1 The OpenJMS install pre-configures this queue by default;


                    whats the equivalent in JBoss ?

                    • 22. Re: JMS problem
                      jaikiran

                      Queues already configured by jboss are mentioned in jbossmq-destinations-service.xml in server/default/deploy/jms directory.

                      One of them is a queue by the name "A".

                      You can lookup this queue in your application.

                      • 23. Re: JMS problem
                        matrix1234

                         

                        javac -classpath .;e:\j2ee.jar;c:\jboss\client\jbossall-client.jar
                         QueueSend.java===>compiled fine.
                        
                        
                        
                        
                        java -classpath .;e:\j2ee.jar;c:\jboss\client\jbossall-client.jar
                        QueueSend
                        javax.naming.NameNotFoundException: A not bound
                         at org.jnp.server.NamingServer.getBinding(NamingServer.java:491)
                         at org.jnp.server.NamingServer.getBinding(NamingServer.java:499)
                         at org.jnp.server.NamingServer.getObject(NamingServer.java:505)
                         at org.jnp.server.NamingServer.lookup(NamingServer.java:278)
                         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
                        java:39)
                         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
                        sorImpl.java:25)
                         at java.lang.reflect.Method.invoke(Method.java:324)
                         at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:261)
                         at sun.rmi.transport.Transport$1.run(Transport.java:148)
                         at java.security.AccessController.doPrivileged(Native Method)
                         at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
                         at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:4
                        60)
                         at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport
                        .java:701)
                         at java.lang.Thread.run(Thread.java:534)
                         at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Unknow
                        n Source)
                         at sun.rmi.transport.StreamRemoteCall.executeCall(Unknown Source)
                         at sun.rmi.server.UnicastRef.invoke(Unknown Source)
                         at org.jnp.server.NamingServer_Stub.lookup(Unknown Source)
                         at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:610)
                         at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:572)
                         at javax.naming.InitialContext.lookup(Unknown Source)
                         at QueueSend.main(QueueSend.java:39)
                        
                        
                        



                        here is the latest code.

                        import java.util.Hashtable;
                        
                        import javax.jms.JMSException;
                        import javax.jms.Queue;
                        import javax.jms.QueueConnection;
                        import javax.jms.QueueConnectionFactory;
                        import javax.jms.QueueSender;
                        import javax.jms.QueueSession;
                        import javax.jms.Session;
                        import javax.jms.TextMessage;
                        import javax.naming.Context;
                        import javax.naming.InitialContext;
                        import javax.naming.NamingException;
                        
                        public class QueueSend
                        {
                         public static void main(String[] args)
                         {
                         try
                         {
                         // create a JNDI context
                         Hashtable env = new Hashtable();
                         env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
                         env.put(Context.PROVIDER_URL, "jnp://localhost:1099");
                         env.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
                         Context context = new InitialContext(env);
                        
                        
                         // retrieve queue connection factory
                         QueueConnectionFactory queueConnectionFactory = (QueueConnectionFactory)context.lookup("ConnectionFactory");
                         // create a queue connection
                         QueueConnection queueConnection = queueConnectionFactory.createQueueConnection();
                        
                         // create a queue session
                         // set transactions to false and set auto acknowledgement of receipt of messages
                         QueueSession queueSession = queueConnection.createQueueSession(false,Session.AUTO_ACKNOWLEDGE);
                        
                         // retrieve queue
                         Queue queue = (Queue)context.lookup("A");
                        
                         // create a queue sender and associate to the retrieved queue
                         QueueSender queueSender = queueSession.createSender(queue);
                        
                         // send a message to the queue
                         TextMessage message = queueSession.createTextMessage();
                         message.setText("Hello there.");
                         queueSender.send(message);
                        
                         System.out.println("Sample application writing message to queue.");
                        
                         // clean up
                         queueSender.close();
                         queueSession.close();
                         queueConnection.close();
                        
                         }
                         catch (NamingException e)
                         {
                         e.printStackTrace();
                         }
                         catch (JMSException e)
                         {
                         e.printStackTrace();
                         }
                        
                        
                         }
                        }
                        
                        
                        


                        here is the proof my Jboss is running...

                        ........................
                        .........................
                        .........................
                        21:46:09,062 INFO [ChannelSocket] JK: ajp13 listening on /0.0.0.0:8009
                        21:46:09,078 INFO [JkMain] Jk running ID=0 time=0/78 config=null
                        21:46:09,140 INFO [Server] JBoss (MX MicroKernel) [4.0.2 (build: CVSTag=JBoss_4
                        _0_2 date=200505022023)] Started in 35s:890ms
                        
                        


                        Its not working .


                        N.B : do i need to restart Jboss everytime ? i did not do it though. becoz i have not deployed..and i am running from command line.

                        • 24. Re: JMS problem
                          jaikiran

                           

                          "Matrix1234" wrote:

                          // retrieve queue
                          Queue queue = (Queue)context.lookup("A");


                          Instead, do the following:
                          // retrieve queue
                          Queue queue = (Queue)context.lookup("queue/A");


                          "Matrix1234" wrote:

                          N.B : do i need to restart Jboss everytime ? i did not do it though. becoz i have not deployed..and i am running from command line.


                          No, you need not restart jboss


                          • 25. Re: JMS problem
                            matrix1234

                            sir, you are a very big programmer.

                            my problem has been solved. everything is working fine.
                            thank you.


                            may be someday someone may want to learn JMS i am sharing my full code snippet here..


                            first start your Jboss server and then .....

                            To Send a message
                            ==================

                            import java.util.Hashtable;
                            
                            import javax.jms.JMSException;
                            import javax.jms.Queue;
                            import javax.jms.QueueConnection;
                            import javax.jms.QueueConnectionFactory;
                            import javax.jms.QueueSender;
                            import javax.jms.QueueSession;
                            import javax.jms.Session;
                            import javax.jms.TextMessage;
                            import javax.naming.Context;
                            import javax.naming.InitialContext;
                            import javax.naming.NamingException;
                            
                            public class QueueSend
                            {
                             public static void main(String[] args)
                             {
                             try
                             {
                             // create a JNDI context
                             Hashtable env = new Hashtable();
                             env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
                             env.put(Context.PROVIDER_URL, "jnp://localhost:1099");
                             env.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
                             Context context = new InitialContext(env);
                            
                            
                             // retrieve queue connection factory
                             QueueConnectionFactory queueConnectionFactory = (QueueConnectionFactory)context.lookup("ConnectionFactory");
                             // create a queue connection
                             QueueConnection queueConnection = queueConnectionFactory.createQueueConnection();
                            
                             // create a queue session
                             // set transactions to false and set auto acknowledgement of receipt of messages
                             QueueSession queueSession = queueConnection.createQueueSession(false,Session.AUTO_ACKNOWLEDGE);
                            
                             // retrieve queue
                             Queue queue = (Queue)context.lookup("queue/A");
                            
                             // create a queue sender and associate to the retrieved queue
                             QueueSender queueSender = queueSession.createSender(queue);
                            
                             // send a message to the queue
                             TextMessage message = queueSession.createTextMessage();
                             message.setText("Hello there.");
                             queueSender.send(message);
                            
                             System.out.println("Sample application writing message to queue.");
                            
                             // clean up
                             queueSender.close();
                             queueSession.close();
                             queueConnection.close();
                            
                             }
                             catch (NamingException e)
                             {
                             e.printStackTrace();
                             }
                             catch (JMSException e)
                             {
                             e.printStackTrace();
                             }
                            
                            
                             }
                            }
                            
                            
                            


                            compile it
                            ==========

                            javac -classpath .;e:\j2ee.jar;c:\jboss\client\jbossall-client.jar
                            QueueSend.java ===>compiles

                            run it
                            ========
                            java -classpath .;e:\j2ee.jar;c:\jboss\client\jbossall-client.jar
                            QueueSend


                            Sample application writing message to queue.






                            To Receive a message Synchronously
                            ====================================
                            
                            import java.util.Hashtable;
                            
                            import javax.jms.JMSException;
                            import javax.jms.Queue;
                            import javax.jms.QueueConnection;
                            import javax.jms.QueueConnectionFactory;
                            import javax.jms.QueueReceiver;
                            import javax.jms.QueueSession;
                            import javax.jms.Session;
                            import javax.jms.TextMessage;
                            import javax.jms.Message;
                            import javax.naming.Context;
                            import javax.naming.InitialContext;
                            import javax.naming.NamingException;
                            
                            
                            public class QueueReceiveSynchronous
                             {
                             public static void main(String[] args)
                             {
                             try
                             {
                             // standard boilerplate code to establish a JNDI
                             // context and connection
                            
                             Hashtable env = new Hashtable();
                             env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
                             env.put(Context.PROVIDER_URL, "jnp://localhost:1099");
                             env.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
                             Context context = new InitialContext(env);
                            
                             // retrieve queue connection factory
                             QueueConnectionFactory queueConnectionFactory = (QueueConnectionFactory)context.lookup("ConnectionFactory");
                            
                            
                            
                             // create a queue connection
                             QueueConnection queueConnection =
                             queueConnectionFactory.createQueueConnection();
                            
                             // start delivery of incoming messages
                             queueConnection.start();
                            
                             // create a queue session
                             // set transactions to false and set auto
                             // acknowledgement of receipt of messages
                             QueueSession queueSession =
                             queueConnection.createQueueSession(
                             false,Session.AUTO_ACKNOWLEDGE);
                            
                             // retrieve queue
                             Queue queue =
                             (Queue)context.lookup("queue/A");
                            
                             // create a queue receiver and associate
                             // to the retrieved queue
                             QueueReceiver queueReceiver =
                             queueSession.createReceiver(queue);
                            
                             // receive message using the synchronous
                             // receive method
                             Message message = queueReceiver.receive();
                             String messageText = null;
                             if (message instanceof TextMessage)
                             messageText =
                             ((TextMessage)message).getText();
                             System.out.println(messageText);
                            
                             // clean up
                             queueReceiver.close();
                             queueSession.close();
                             queueConnection.close();
                            
                             }
                             catch (NamingException e)
                             {
                             e.printStackTrace();
                             }
                             catch (JMSException e)
                             {
                             e.printStackTrace();
                             }
                             }
                             }
                            



                            compile it
                            ==========
                            javac -classpath .;e:\j2ee.jar;c:\jboss\client\jbossall-client.jar
                            QueueReceiveSynchronous.java===>compiles fine


                            Run it
                            ======

                            java -classpath .;e:\j2ee.jar;c:\jboss\client\jbossall-client.jar
                            QueueReceiveSynchronous
                            Hello there.














                            To Receive the mesasage Asynchronously
                            =======================================
                            import java.util.Hashtable;
                            
                            import javax.jms.JMSException;
                            import javax.jms.Message;
                            import javax.jms.MessageListener;
                            import javax.jms.Queue;
                            import javax.jms.QueueConnection;
                            import javax.jms.QueueConnectionFactory;
                            import javax.jms.QueueReceiver;
                            import javax.jms.QueueSession;
                            import javax.jms.Session;
                            import javax.jms.TextMessage;
                            import javax.naming.Context;
                            import javax.naming.InitialContext;
                            import javax.naming.NamingException;
                            
                            public class QueueReceiveAsynchronous implements MessageListener
                            {
                            
                             private QueueConnection queueConnection;
                             private QueueSession queueSession;
                             private Queue queue;
                             private QueueReceiver queueReceiver;
                            
                             QueueReceiveAsynchronous()
                             {
                             try
                             {
                             // create a JNDI context
                             Hashtable env = new Hashtable();
                             env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
                             env.put(Context.PROVIDER_URL, "jnp://localhost:1099");
                             env.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
                             Context context = new InitialContext(env);
                            
                             // retrieve queue connection factory
                             QueueConnectionFactory queueConnectionFactory = (QueueConnectionFactory)context.lookup("ConnectionFactory");
                            
                             // create a queue connection
                             queueConnection =
                             queueConnectionFactory.createQueueConnection();
                            
                             // create a queue session
                             // set transactions to false and set auto
                             // acknowledgement of receipt of messages
                             queueSession = queueConnection.createQueueSession(
                             false,Session.AUTO_ACKNOWLEDGE);
                            
                             // retrieve queue
                             queue = (Queue)context.lookup("queue/A");
                            
                             // create a queue receiver and associate
                             // to the retrieved queue
                             queueReceiver = queueSession.createReceiver(queue);
                            
                             // associate message listener
                             queueReceiver.setMessageListener(this);
                            
                             // start delivery of incoming messages
                             queueConnection.start();
                             }
                             catch (NamingException e)
                             {
                             e.printStackTrace();
                             }
                             catch (JMSException e)
                             {
                             e.printStackTrace();
                             }
                             }
                            
                             public static void main(String[] args)
                             {
                             System.out.println(
                             "Example to asynchronously listen to a queue.");
                             try
                             {
                             QueueReceiveAsynchronous listener =
                             new QueueReceiveAsynchronous();
                             Thread.currentThread().sleep(2000);
                             }
                            
                             catch (InterruptedException e)
                             {
                             e.printStackTrace();
                             }
                             }
                            
                             // process incoming messages
                             public void onMessage(Message message)
                             {
                             try
                             {
                             String messageText = null;
                             if (message instanceof TextMessage)
                             messageText = ((TextMessage)message).getText();
                             System.out.println(messageText);
                             }
                             catch (JMSException e)
                             {
                             e.printStackTrace();
                             }
                             }
                            }
                            



                            compile it
                            ===========
                            javac -classpath .;e:\j2ee.jar;c:\jboss\client\jbossall-client.jar
                            QueueReceiveAsynchronous.java ==>compiles fine.



                            Run it
                            ======
                            java -classpath .;e:\j2ee.jar;c:\jboss\client\jbossall-client.jar
                            QueueReceiveAsynchronous
                            Example to asynchronously listen to a queue.
                            Hello there.
                            





                            ALL thsese works.


                            • 26. Re: JMS problem
                              matrix1234

                              i want to keep QueueSend class in machine-1's Jboss and want to receive message in machine-2's JBoss. both machines are LAN connected.

                              is hat possible ?

                              what necessary code changes i have to do ?

                              • 27. Re: JMS problem
                                matrix1234

                                right now, all my classes are in the same machine.

                                which i dont like.
                                i want to put my sender class in machine-1 and want to put my Receiver class in machine-2. is that possible ?

                                • 28. Re: JMS problem
                                  jaikiran
                                  • 29. Re: JMS problem
                                    matrix1234

                                    supose,

                                    IP of machine-1 is 200.24.56.75

                                    IP of machine-2 is 215.25.56.78

                                    i want to keep my QueueSend class in machine-1.
                                    and i want to receive message in machine-2 from the QueueReceiveSynchronous class.

                                    both the machine has same version of JBoss.

                                    i visited the link but i am not feeling comfortable .
                                    i have JBoss version 4.0.

                                    please tell me the simple steps so that i can follow. as you see, i am very much newbie, so plz provide some guidelines/code snippets to test this.


                                    regards