title: JBoss AS 7 simple hello world application
body: <p>I am trying to get a simple JMS "Hello world" application to run. I would like to try it out on JBoss Application Server 7 but i am not able to run it. Jboss as HornetQ embedden in it and i started it using the following command:</p>
  
  <pre><code>standalone.bat --server-config=standalone-preview.xml
  </code></pre>
  
  <p>I think the problem is most likely to the way i have configured the queue within JBoss. Here are the steps i did. </p>
  
  <ul>
  <li>Configure queue</li>
  </ul>
  
  <p>Quene name: testQueue
  JNDI name: queue/test</p>
  
  <p>The queue configuration has an option for "Selector". Can this be left blank and if not, what goes in this field?</p>
  
  <ul>
  <li>Code </li>
  </ul>
  
  <p>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. </p>
  
  <pre><code>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();
      }
  }
  </code></pre>
  
  <p>When i run the above class i get the following error:</p>
  
  <pre><code>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)
  </code></pre>
  
  <p>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?</p>
  
  <h2>Edit</h2>
  
  <p>Most of the documentation seem to refer to JBoss AS 6. I have updated the code snippet to include   the following:</p>
  
  <pre><code>Properties env = new Properties();
      env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory" );
      env.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
      env.put(Context.PROVIDER_URL, "jnp://localhost:1199");
      ctx = new InitialContext(env);
  </code></pre>
  
  <p>I am now getting classNotFound exception. I think it needs an additional jar file to be added to the classpath but which one???</p>
  
  <pre><code>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: Cannot instantiate class: org.jnp.interfaces.NamingContextFactory [Root exception is java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory]
              at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
              at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
              at javax.naming.InitialContext.init(Unknown Source)
              at javax.naming.InitialContext.&lt;init&gt;(Unknown Source)
              at jms.ex3.Sender.main(Sender.java:27)
      Caused by: java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory
              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 com.sun.naming.internal.VersionHelper12.loadClass(Unknown Source)
              ... 5 more
  </code></pre>