<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">

<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>

                                <td>

                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="https://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>

                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px;  -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
    Hi there
</h3>
<span style="margin-bottom: 10px;">
    created by <a href="https://community.jboss.org/people/haithamnor">Haitham Safi</a> in <i>JNDI and Naming</i> - <a href="https://community.jboss.org/message/787525#787525">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">

<div class="jive-rendered-content"><p>i'm new with JMS and i wrote the folloing example</p><p>import java.io.*;</p><p>&#160; import javax.jms.*;</p><p>import javax.naming.Context;</p><p>import javax.naming.InitialContext;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p> public class Qsender </p><p>{</p><p>public static void main(String[] args) {</p><p>&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;new Qsender().send();</p><p>}</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>public void send() {</p><p>&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));</p><p>try {</p><p>&#160; </p><p>//Prompt for JNDI names</p><p>&#160;&#160;&#160; </p><p>&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;System.out.println("Enter QueueConnectionFactory name:");</p><p>&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;String factoryName = reader.readLine();</p><p>&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;System.out.println("Enter Queue name:");</p><p>&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;String queueName = reader.readLine();</p><p>&#160; </p><p>&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;//Look up administered objects</p><p>&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;InitialContext initContext = new InitialContext();</p><p>&#160; </p><p>&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;QueueConnectionFactory factory =(QueueConnectionFactory) initContext.lookup(factoryName);</p><p>&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;Queue queue = (Queue) initContext.lookup(queueName);</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;initContext.close();</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;//Create JMS objects</p><p>&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;QueueConnection connection = factory.createQueueConnection();</p><p>&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;QueueSession session =&#160;&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);</p><p>&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;QueueSender sender = session.createSender(queue);</p><p>//Send messages</p><p>&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;String messageText = null;</p><p>while (true) {</p><p>&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;System.out.println("Enter message to send or 'quit':");</p><p>&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;messageText = reader.readLine();</p><p>&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;if ("quit".equals(messageText))</p><p>&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;break;</p><p>&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;TextMessage message = session.createTextMessage(messageText);</p><p>&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;sender.send(message);</p><p>}</p><p>//Exit</p><p>System.out.println("Exiting...");</p><p>&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;reader.close();</p><p>&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;connection.close();</p><p>&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;System.out.println("Goodbye!");</p><p>} catch (Exception e) {</p><p>&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;e.printStackTrace();</p><p>&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;System.exit(1);</p><p>}</p><p>}</p><p>}</p><p>i have Jboss v5 App server but at execut the code i recived this error</p><p>javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:&#160; java.naming.factory.initial</p><p>&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)</p><p>&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)</p><p>&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;at javax.naming.InitialContext.getURLOrDefaultInitCtx(Unknown Source)</p><p>&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;at javax.naming.InitialContext.lookup(Unknown Source)</p><p>&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;at Qsender.send(Qsender.java:32)</p><p>&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;at Qsender.main(Qsender.java:13)</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Some one can help me</p><p>thx</p></div>

<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
    <p style="margin: 0;">Reply to this message by <a href="https://community.jboss.org/message/787525#787525">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in JNDI and Naming at <a href="https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2083">Community</a></p>
</div></td>
                        </tr>
                    </tbody>
                </table>


                </td>
            </tr>
        </tbody>
    </table>

</div>

</body>
</html>