jms for weblogic

示例代码:


import java.util.Hashtable;
import java.util.Properties;

import javax.jms.*;
import javax.naming.*;

public class QueneSend{

/**
* @param args
* @throws NamingException
* @throws JMSException
*/
public static void main(String[] args) throws NamingException, JMSException {
// TODO Auto-generated method stub
String queueName="TestQueue";
System.out.println("QUEUE NAME IS:" +queueName);
Properties properties=new Properties();
properties.setProperty(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
properties.setProperty(Context.PROVIDER_URL,"t3://localhost:7001");
Context jndiContext=new InitialContext(properties);
QueueConnectionFactory qFactory=(QueueConnectionFactory)jndiContext.lookup("TestQueueFactory");
QueueConnection qConnection=qFactory.createQueueConnection();
QueueSession qSession=qConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue=(Queue)jndiContext.lookup(queueName);
QueueSender qSender=qSession.createSender(queue);
TextMessage message=qSession.createTextMessage();
for (int i = 1; i < 4; i++) {
message.setText("队列"+i+"测试 ");
System.out.println(message.getText());
qSender.send(message);
}
Message message2=qSession.createMessage();
if(qSession!=null)
qSession.close();
}

}



运行条件:
导入:wlclient.jar、wljmsclient.jar两个jar包(在WEBLOGIC安装目录的lib地下,如:bea\weblogic81\server\lib),WEBLOGIC用8.0版本,jdk1.4版本。
配置weblogic工厂步骤:
1、新建jms连接工厂,工厂名称为“TestQueueFactory”:
2、新建jms服务器,服务器名称为:“TestQueueJmsServer”:
3、在“TestQueueJmsServer”服务下新建目标为“TestQueue”队列:


错误解决:
错误1:
显示“javax.naming.NoInitialContextException: Cannot instantiate class: weblogic.jndi.WLInitialContextFactory ” 为什么编译没问题了,却还是出错呢,这是网络上问得最多的问题。这是缺少"\bea\weblogic81\server\lib\wlclient.jar"文件所致。 在buildpath里加入这个包后再运行。

如果还是出错,显示“Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/corba/se/connection/ORBSocketFactory” 还是缺少包,这时如果你只安装有jre1.5.*,那是没有ORBSocketFactory这个类文件的。还是找个jre1.4.*吧,这个类在“jre/lib/rt.jar”包中。据说这个问题在weblogic9中已解决。

错误2:
java.lang.IllegalAccessError: tried to access method weblogic.kernel.KernelStatus.initialized()V from class weblogic.kernel.Kernel

使用wljmsclient.jar和wlclient.jar替换jms.jar和weblogic.jar
即可
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值