Cannot instantiate class: org.jboss.naming.remote.client.InitialContextFactory in Three Tier Architecture

StackOverflow https://stackoverflow.com/questions/16851418

  •  30-05-2022
  •  | 
  •  

Question

I am trying to connect jboss 7.1.1 final with Three tier architecture approach keeping connection logic in my business layer and access this business layer from my presentation layer. But it is throwing following exception

Cannot instantiate class: org.jboss.naming.remote.client.InitialContextFactory.

It's working fine if i keep jboss connection logic in same presentation layer.

following is my code in business logic.

public static void Connect()
    {
        try
        {
            javax.naming.Context context = null;
            ConnectionFactory connectionFactory;
            Connection connection;
            Session session;
            String topicName = "jms/topic/TestedTopic";
            Destination dest = null;
            MessageConsumer consumer = null;
            TextListener listener = null;
            java.util.Properties jndiProps = new java.util.Properties();
            jndiProps.put(Context.__Fields.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
            jndiProps.put(Context.__Fields.PROVIDER_URL, "remote://10.1.7.149:4447");
            jndiProps.put(Context.__Fields.SECURITY_PRINCIPAL, "admin");
            jndiProps.put(Context.__Fields.SECURITY_CREDENTIALS, "admin123");
            jndiProps.put("jboss.naming.client.ejb.context", true);


            context = new InitialContext(jndiProps);


            connectionFactory = (ConnectionFactory)context.lookup("jms/RemoteConnectionFactory");
            connection = connectionFactory.createConnection();
            dest = (Destination)context.lookup(topicName);
            session = connection.createSession(false, Session.__Fields.AUTO_ACKNOWLEDGE);
            consumer = session.createConsumer(dest);

            listener = new TextListener();
            consumer.setMessageListener(listener);
            connection.start();
        }
        catch (Exception)
        {

            //throw;
        }
    }
Was it helpful?

Solution

This is follow exception of a ClassNotFoundException. See the wiki for a solution.

OTHER TIPS

Adding a reference to Visual Studio does not add a reference in the compiled output. Only if you use one class in your code and not via reflection a reference is added.

There are 3 options: The best is you use a full qualified .NET classname. This include also the dll name.

Or you use BootClassPathAssemby like in http://sourceforge.net/apps/mediawiki/ikvm/index.php?title=ClassLoader

Or you use one class file from the dll and use the AppDomainAssemblyClassLoader. Details are at http://sourceforge.net/apps/mediawiki/ikvm/index.php?title=ClassLoader

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top