當我嘗試在JMS中運行QUEUE:Producer代碼時拋出錯誤。Glassfish服務器JMS獨立隊列
了java.lang.RuntimeException:初始化ORB erorr javax.naming.NamingException中:查找在SerialContext [myEnv = {java.naming.factory.initial的= com.sun.enterprise.naming.impl失敗 'myQueueConnectionFactory'。 SerialInitContextFactory,java.naming.factory.url.pkgs = com.sun.enterprise.naming,java.naming.factory.state = com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl} [根異常是javax。 naming.NamingException:無法獲取SerialContext的SerialContextProvider [myEnv = {java.naming.factory.initial = com.sun.enterprise.naming.impl.SerialInitContextFactory,java.naming.factory.url.pkgs = com.sun.enterprise。命名,java.naming.factory.state = com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl} [根異常是java.lang.RuntimeException:Orb初始化錯誤]]
我的代碼是:
//Create and start connection
InitialContext ctx=new InitialContext();
QueueConnectionFactory f=(QueueConnectionFactory)ctx.lookup("myQueueConnectionFactory");
QueueConnection con=f.createQueueConnection();
con.start();
//2) create queue session
QueueSession ses=con.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
//3) get the Queue object
Queue t=(Queue)ctx.lookup("myQueue");
//4)create QueueSender object
QueueSender sender=ses.createSender((t));
//5) create TextMessage object
TextMessage msg=ses.createTextMessage();