Exception in thread "main" javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or in an application resource file: java.naming.factory.initial at java.naming/javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:685) at java.naming/javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:305) at java.naming/javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:342) at java.naming/javax.naming.InitialContext.lookup(InitialContext.java:409) at br.com.caelum.jms.TesteConsumidor.main(TesteConsumidor.java:19)
Estou com esse erro na saida do activemq, alguém poderia me ajudar com esse erro ?
Vou mandar meu código:
package br.com.caelum.jms;
import java.util.Scanner;
import javax.jms.Connection; import javax.jms.ConnectionFactory; import javax.jms.Destination; import javax.jms.Message; import javax.jms.MessageConsumer; import javax.jms.Session; import javax.naming.InitialContext;
public class TesteConsumidor {
@SuppressWarnings("resource")
public static void main(String[] args) throws Exception {
InitialContext context = new InitialContext();
ConnectionFactory factory = (ConnectionFactory) context.lookup("ConnectionFactory");
Connection connection = factory.createConnection();
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Destination fila = (Destination) context.lookup("financeiro");
MessageConsumer consumer = session.createConsumer(fila );
Message message = consumer.receive();
System.out.println("Recebendo msg: " + message);
new Scanner(System.in).nextLine();
session.close();
connection.close();
context.close();
}
}