[jboss-user] [JBoss Messaging] - JBoss exception when sending message to IBM MQ

seanshih do-not-reply at jboss.com
Mon Feb 25 16:47:36 EST 2008


Hi,
I got this error when I run my java code:
Could not create JNDI API context: javax.naming.NoInitialContextException: Cannot instantiate class: java.naming.factory.init ial [Root exception is java.lang.ClassNotFoundException: java.naming.factory.initial]


Can someone tell me what went wrong in my code?
***********************************************
import java.lang.*;
import javax.jms.*;
import javax.naming.*;
import java.util.Properties;

public class IBMMQSender {

    public static void main(String[] args) {
        String                  queueName = null;
        InitialContext          jndiContext = null;
        QueueConnectionFactory  queueConnectionFactory = null;
        QueueConnection         queueConnection = null;
        QueueSession            queueSession = null;
        Queue                   queue = null;
        QueueSender             queueSender = null;
        TextMessage             message = null;
        final int               NUM_MSGS;

        if ( (args.length < 1) || (args.length > 2) ) {
            System.out.println("Usage: java IBMMQSender " +
                "<queue-name> [<number-of-messages>]");
            System.exit(1);
        }
        queueName = new String(args[0]);
        System.out.println("Queue name is " + queueName);
        if (args.length == 2){
            NUM_MSGS = (new Integer(args[1])).intValue();
        } else {
            NUM_MSGS = 1;
        }

        /*
         * Create a JNDI API InitialContext object if none exists
         * yet.
         */
        try {
            Properties properties = new Properties();
            properties.put(Context.INITIAL_CONTEXT_FACTORY, "java.naming.factory.initial");
            properties.put(Context.URL_PKG_PREFIXES, "java.naming.factory.url.pkgs");
            properties.put(Context.PROVIDER_URL, "java.naming.provider.url");
            jndiContext = new InitialContext(properties);
            //jndiContext = new InitialContext();
        } catch (NamingException e) {
            System.out.println("Could not create JNDI API " +
                "context: " + e.toString());
            System.exit(1);
        }



View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4131993#4131993

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4131993



More information about the jboss-user mailing list