1 Reply Latest reply on Jan 5, 2013 8:51 AM by Wolf-Dieter Fink

    Hi there

    Haitham Safi Newbie

      i'm new with JMS and i wrote the folloing example

      import java.io.*;

        import javax.jms.*;

      import javax.naming.Context;

      import javax.naming.InitialContext;

       

      public class Qsender

      {

      public static void main(String[] args) {

                new Qsender().send();

      }

       

       

       

       

      public void send() {

                BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

      try {

       

      //Prompt for JNDI names

         

                System.out.println("Enter QueueConnectionFactory name:");

                String factoryName = reader.readLine();

                System.out.println("Enter Queue name:");

                String queueName = reader.readLine();

       

                //Look up administered objects

                InitialContext initContext = new InitialContext();

       

                QueueConnectionFactory factory =(QueueConnectionFactory) initContext.lookup(factoryName);

                Queue queue = (Queue) initContext.lookup(queueName);

       

                initContext.close();

       

                 //Create JMS objects

                QueueConnection connection = factory.createQueueConnection();

                QueueSession session =           connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);

                QueueSender sender = session.createSender(queue);

      //Send messages

                String messageText = null;

      while (true) {

                System.out.println("Enter message to send or 'quit':");

                messageText = reader.readLine();

                if ("quit".equals(messageText))

                break;

                TextMessage message = session.createTextMessage(messageText);

                sender.send(message);

      }

      //Exit

      System.out.println("Exiting...");

                reader.close();

                connection.close();

                System.out.println("Goodbye!");

      } catch (Exception e) {

                e.printStackTrace();

                System.exit(1);

      }

      }

      }

      i have Jboss v5 App server but at execut the code i recived this error

      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 Qsender.send(Qsender.java:32)

                at Qsender.main(Qsender.java:13)

       

      Some one can help me

      thx