OpenJMS:上下文创建失败并出现 InvalideClassException
我将 OpenJMS 与 NetBeans 6.9.1 结合使用。我创建了一个简单的 NetBeans 平台应用程序和其中的一个模块。我已经使用其startup.bat 文件启动了openjms-0.7.7-beta。现在,在模块中执行以下代码以开始侦听有关主题的消息。
factoryName = "ConnectionFactory";
String topicName = "topic1";
String initialContext = "org.exolab.jms.jndi.InitialContextFactory";
String providerURL = "tcp://localhost:3035/";
Hashtable properties = new Hashtable();
properties.put(Context.INITIAL_CONTEXT_FACTORY, initialContext);
properties.put(Context.PROVIDER_URL, providerURL);
context = new InitialContext(properties);
factory = (ConnectionFactory) context.lookup(factoryName);
dest = (Destination) context.lookup(topicName);
connection = factory.createConnection();
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
receiver = session.createConsumer(dest);
receiver.setMessageListener(this);
connection.start();
该代码在一个简单的 java 应用程序中完美运行,但在此配置中它失败了;
context = new InitialContext(properties);
这是异常
javax.naming.CommunicationException: Failed to lookup JNDI provider for URL: tcp://localhost:3035/ [Root exception is java.rmi.UnmarshalException: Failed to unmarshal response; nested exception is:
java.io.InvalidClassException: org.exolab.jms.server.net.RemoteNamingProvider__Proxy; local class incompatible: stream classdesc serialVersionUID = 8042785765194780386, local class serialVersionUID = 3384686210958076383]
at org.exolab.jms.jndi.InitialContextFactory.getInitialContext(InitialContextFactory.java:160)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:667)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
at javax.naming.InitialContext.init(InitialContext.java:223)
at javax.naming.InitialContext.<init>(InitialContext.java:197)
在我看来,此客户端代码将“org.exolab.jms.server.net.RemoteNamingProvider__Proxy”类的对象发送到 openJMS 服务器。该类位于代码和 openJMS 服务器使用的同一个 JAR 文件中。然而,由于某些奇怪的原因,编译器该类在服务器端具有不同的序列 ID。
我在网上寻找线索。如果我们使用不同的编译器,一个类的序列号可能会不同。我不知道 openJMS 服务器是否使用除我计算机上安装的 Java SE 编译器之外的编译器。不过,我确信 NetBeans 正在使用它(Java SE 编译器)来编译此客户端代码。
其次,我无法显式地将序列 id 分配给引发异常的类,因为它位于 openJMS 库中,而不是我自己的类中。
任何帮助将不胜感激。
-哈达图拉
I am using OpenJMS with NetBeans 6.9.1. I have created a simple NetBeans Platform Application and a module inside it. I have started my openjms-0.7.7-beta using its startup.bat file. Now in the module the following code executes to start listening for messages on a topic.
factoryName = "ConnectionFactory";
String topicName = "topic1";
String initialContext = "org.exolab.jms.jndi.InitialContextFactory";
String providerURL = "tcp://localhost:3035/";
Hashtable properties = new Hashtable();
properties.put(Context.INITIAL_CONTEXT_FACTORY, initialContext);
properties.put(Context.PROVIDER_URL, providerURL);
context = new InitialContext(properties);
factory = (ConnectionFactory) context.lookup(factoryName);
dest = (Destination) context.lookup(topicName);
connection = factory.createConnection();
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
receiver = session.createConsumer(dest);
receiver.setMessageListener(this);
connection.start();
The code worked perfectly in a simple java application but in this configuration it fails on the line;
context = new InitialContext(properties);
Here is the Exeception
javax.naming.CommunicationException: Failed to lookup JNDI provider for URL: tcp://localhost:3035/ [Root exception is java.rmi.UnmarshalException: Failed to unmarshal response; nested exception is:
java.io.InvalidClassException: org.exolab.jms.server.net.RemoteNamingProvider__Proxy; local class incompatible: stream classdesc serialVersionUID = 8042785765194780386, local class serialVersionUID = 3384686210958076383]
at org.exolab.jms.jndi.InitialContextFactory.getInitialContext(InitialContextFactory.java:160)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:667)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
at javax.naming.InitialContext.init(InitialContext.java:223)
at javax.naming.InitialContext.<init>(InitialContext.java:197)
It appears to me that this client code sends an object of class "org.exolab.jms.server.net.RemoteNamingProvider__Proxy" to the openJMS server. The class is located in same JAR file used by both the code and openJMS server. For some strange reason, however, compiler the class is having different serial ID on the server side.
I searched the internet for clues. Serial ids of a class can be different if we use different compilers. I don't know if openJMS server is using a compiler other than my Java SE compiler installed on my computer. However, I am sure that NetBeans is using it (Java SE compiler) for this client code compilation.
Secondly, I can't explicitly assign serial id to the exception causing class becuase it is in openJMS library and not my own class.
Any help will be appreciated.
-Hadaytullah
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论