1 Reply Latest reply on Feb 26, 2008 3:52 AM by ataylor

    JBoss exception when sending message to IBM MQ

    seanshih

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

        • 1. Re: JBoss exception when sending message to IBM MQ
          ataylor

           

          properties.put(Context.INITIAL_CONTEXT_FACTORY, "java.naming.factory.initial");


          The property you set here should be the class that is used to create the InitialContext, for JBoss this is 'org.jnp.interfaces.NamingContextFactory', you'll have to check the IBM MQ documentation to find the name of their Context Factory