1 Reply Latest reply on Jan 5, 2013 8:51 AM by wdfink

    Hi there


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




                 //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))


                TextMessage message = session.createTextMessage(messageText);








      } catch (Exception e) {






      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


        • 1. Re: Hi there

          You need to put some properties in the InitialContext(....), i.e. the host, port ....

          See wiki pages, documentation and tutorials for your JBoss version