java - javax.naming.NoInitialContextException in simple jms app -



java - javax.naming.NoInitialContextException in simple jms app -

import java.util.properties; import javax.jms.*; import javax.naming.*; public class topicconsumer implements messagelistener { public static void main(string[] args) throws jmsexception, namingexception { system.out.println("------>starting jms topicconsumer<----"); context context= topicconsumer.getinitialcontext(); system.out.println(">>>1<<<"); topicconnectionfactory topicconnectionfactory= (topicconnectionfactory)context.lookup("connectionfactory"); system.out.println(">>>2<<<"); topic topic= (topic) context.lookup("topic/akshay"); system.out.println(">>>3<<<"); topicconnection topicconnection= topicconnectionfactory.createtopicconnection(); system.out.println(">>>4<<<"); topicsession topicsession= topicconnection.createtopicsession(false,topicsession.auto_acknowledge); system.out.println(">>>5<<<"); topicsession.createsubscriber(topic).setmessagelistener(new topicconsumer()); system.out.println(">>>6<<<"); topicconnection.start(); system.out.println("------>Énding jms topicconsumer<----"); } @override public void onmessage(message message) { seek { system.out.println(">>>on msg<<<"); system.out.println("incoming message is"+((textmessage)message).gettext()); } grab (jmsexception e) { e.printstacktrace(); } } public static context getinitialcontext() throws jmsexception, namingexception{ system.out.println(">>>7<<<"); properties props=new properties(); system.out.println(">>>8<<<"); props.setproperty("java.naming.factory.initial","org.jnp.interfaces.namingcontextfactory"); system.out.println(">>>9<<<"); props.setproperty("java.naming.factory.url.pkgs","org.jboss.naming"); system.out.println(">>>10<<<"); props.setproperty("java.naming.provider.url","localhost:1099"); system.out.println(">>>11<<<"); context context= new initialcontext(); system.out.println(">>>12<<<"); homecoming context; } }

exception in thread "main" javax.naming.noinitialcontextexception: need specify class name in environment or scheme property, or applet parameter, or in application resource file: java.naming.factory.initial @ javax.naming.spi.namingmanager.getinitialcontext(unknown source) @ javax.naming.initialcontext.getdefaultinitctx(unknown source) @ javax.naming.initialcontext.geturlordefaultinitctx(unknown source) @ javax.naming.initialcontext.lookup(unknown source) @ topicproducer.main(topicproducer.java:19)

i new jms.my code this.exception naming exception: seem have problem in setting jndi or classpath. have included next jms.jar file problem in classpath or jndi ...? using eclipse juno jboss 5.0 , jdk 1.7

you forgot include properties while creating context.

so instead of

context context= new initialcontext();

try

context context= new initialcontext(properties);

java jboss jms publish-subscribe

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -