JMS e JNDI recebendo NoInitialContextException

Java

13/09/2014

Pessoal,
Estou usando o JMS e queria usar o arquivo jndi.properties, porém não estou conseguindo e não estou vendo a luz no fim do túnel.
Meu ambiente de desenvolvimento é composto por Linux + KDE, Netbeans 7.4 e Jboss 6.0.0

Meu jndi.properties é seguinte:
javax.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
javax.naming.provider.url=jnp://localhost:1099
javax.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces


JMSUtil:

package br.com.asc.jms;

import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.naming.Context;
import javax.naming.InitialContext;

/**
 *
 * @author rodrigo
 */
public class JMSUtil {
    private static final String CONNECTION_FACTORY = "TopicConnectionFactory";
    
    private static final String TOPIC = "topic/AscTopic";
    
    private static Context jndiContext = null;
    
    public static Object jndiLookup (String jndiName) throws Exception {
        if (jndiContext == null){
            try {
                jndiContext = new InitialContext();
            } catch (Exception e){
                e.printStackTrace();
                throw e;
            }
        }
        return jndiContext.lookup(jndiName);
    }
    
    public static ConnectionFactory getConnectionFactory() throws Exception{
        return (ConnectionFactory) jndiLookup(CONNECTION_FACTORY);
    }
    
    public static Destination getDestination() throws Exception {
        return (Destination) jndiLookup(TOPIC);
    }    
    
}

Todas as vezes que chamo JMSUtil, onde envio a conexão através da chamada da classes, o sistema retorna a seguinte mensagem:

Exception in thread "main" javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:662)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:344)
at javax.naming.InitialContext.lookup(InitialContext.java:411)
at br.com.asc.jms.JMSUtil.jndiLookup(JMSUtil.java:34)
at br.com.asc.jms.JMSUtil.getConnectionFactory(JMSUtil.java:38)
at br.com.asc.jms.StockPublisher.sendMessage(StockPublisher.java:31)
at br.com.asc.jms.StockPublisher.main(StockPublisher.java:47)

O jndi.properties está na pasta lib, mas mesmo colocando o arquivo no mesmo nível que o .jar, eu tenho o mesmo problema.
Alguém tem alguma dica para me ajudar a resolver esta questão?
Rodrigo Passos

Rodrigo Passos

Curtidas 0
POSTAR