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;
}
}
This is follow exception of a ClassNotFoundException. See the wiki for a solution.