6 Replies Latest reply on Dec 19, 2011 9:14 AM by jaikiran pai

    Jboss 7 simple hello world application.

    ~= ziggy =~ Newbie

      Hi all,

       

      I am trying to get a simple JMS "Hello world" application to run. I would like to try it out on Jboss 7 but i am not able to run it. I think the problem is most likely to the way i have configured the queue within Jboss. Here are the steps i did.

       

      - Configure queue

       

      Quene name: testQueue

      JNDI name: queue/test

       

      The queue configuration has an option for "Selector". Can this be left blank and if not, what goes in this field?

       

      - Code

       

      Here is the code i am using as the Sender. I am not worried of the receiver for now as i just want to start sending a message first.

       

      package jms.ex3;

       

      import javax.naming.InitialContext;

       

      import javax.jms.Queue;

      import javax.jms.Session;

      import javax.jms.TextMessage;

      import javax.jms.QueueSender;

      import javax.jms.DeliveryMode;

      import javax.jms.QueueSession;

      import javax.jms.QueueConnection;

      import javax.jms.QueueConnectionFactory;

                                                                                

      public class Sender

      {

          public static void main(String[] args) throws Exception

          {

             // get the initial context

             InitialContext ctx = new InitialContext();

                                                                               

             // lookup the queue object

             Queue queue = (Queue) ctx.lookup("queue/test");

                                                                               

             // lookup the queue connection factory

             QueueConnectionFactory connFactory = (QueueConnectionFactory) ctx.

                 lookup("queue/connectionFactory");

                                                                               

             // create a queue connection

             QueueConnection queueConn = connFactory.createQueueConnection();

                                                                               

             // create a queue session

             QueueSession queueSession = queueConn.createQueueSession(false,

                 Session.DUPS_OK_ACKNOWLEDGE);

                                                                               

             // create a queue sender

             QueueSender queueSender = queueSession.createSender(queue);

             queueSender.setDeliveryMode(DeliveryMode.NON_PERSISTENT);

                                                                              

             // create a simple message to say "Hello"

             TextMessage message = queueSession.createTextMessage("Hello");

                                                                               

             // send the message

             queueSender.send(message);

                                                                               

             // print what we did

             System.out.println("sent: " + message.getText());

                                                                               

             // close the queue connection

             queueConn.close();

          }

      }

       

      When i run the above class i get the following error:

       

      java -classpath C:\Users\702723344\Downloads\glassfish-3.1.1\glassfish3\glassfish\lib\javaee.jar;. jms.ex3.Sender

      Exception in thread "main" javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial

              at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)

              at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)

              at javax.naming.InitialContext.getURLOrDefaultInitCtx(Unknown Source)

              at javax.naming.InitialContext.lookup(Unknown Source)

              at jms.ex3.Sender.main(Sender.java:22)

       

             

      How exactly does the above class know that the Provider(Jboss) is running on the localhost machine? Dont i need to specify an IP address somewhere? Any ideas?