ClassNotFoundException 引用 JBoss AS 7 中的 hornetq 特定内容
我正在尝试在 JBoss AS 7 应用程序中使用 JMS。发布正常消息似乎工作正常,但是当我尝试使用 hornetq 特定功能(排除重复消息)时,会引发异常。 这是代码:
om.setStringProperty(org.hornetq.api.core.Message.HDR_DUPLICATE_DETECTION_ID.toString(), application+rs.getString("stream")+ rs.getInt("site"));
这是堆栈跟踪:
java.lang.ClassNotFoundException: org.hornetq.api.core.Message from [Module "deployment.TestRestEasy.war:main" from Service Module Loader]
org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:191)
org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:361)
org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:333)
org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:310)
org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:103)
sample.Processor.processStreamSite(Processor.java:82)
sample.Processor.processSitesForStream(Processor.java:63)
sample.Processor.process(Processor.java:55)
sample.HelloWorld.process(HelloWorld.java:31)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:140)
org.jboss.resteasy.core.ResourceMethod.invokeOnTarget(ResourceMethod.java:255)
org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:220)
org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:209)
org.jboss.resteasy.core.SynchronousDispatcher.getResponse(SynchronousDispatcher.java:519)
org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:496)
org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:119)
org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:208)
org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:55)
org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:50)
javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
我相信我已经正确配置了standalone.xml 配置文件,因为标准JMS 代码可以正常工作。我需要做什么特殊的事情才能访问 HornetQ 的特定功能吗?
更新: 担心与我正在使用的 RestEasy 相关,因此转移到独立的 Servlet,但仍然遇到同样的问题。下面的代码和异常
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try {
Context ic = new InitialContext();
QueueConnectionFactory qcf = (QueueConnectionFactory) ic.lookup("java:/ConnectionFactory");
Queue q = (Queue) ic.lookup("queue/test");
QueueConnection qc = qcf.createQueueConnection();
QueueSession qsess = qc.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
QueueSender qsend = qsess.createSender(q);
ObjectMessage om = qsess.createObjectMessage();
om.setObject((Serializable)new InboundDirectory("X", "Y", 9));
om.setStringProperty(org.hornetq.api.core.Message.HDR_DUPLICATE_DETECTION_ID.toString(), "X");
qsend.send(om);
System.out.println("X");
}
catch (Exception e) {
e.printStackTrace();
}
}
这是异常:
java.lang.ClassNotFoundException: org.hornetq.api.core.Message from [Module "deployment.TestRestEasy.war:main" from Service Module Loader]
org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:191)
org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:361)
org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:333)
org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:310)
org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:103)
TestServlet.doPost(TestServlet.java:65)
TestServlet.doGet(TestServlet.java:46)
javax.servlet.http.HttpServlet.service(HttpServlet.java:734)
javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
进一步更新: 通过使用字符串值来使其工作,但我认为这并不理想,属性键不能保证永远是该字符串。
om.setStringProperty("_HQ_DUPL_ID", "X:Y:9");
知道正确的方法吗?
更新:感谢@Vadzim 为我指明了正确的方向。对于其他遇到此特定问题的人,我更新了 Manifest.MF,如下所示:
Manifest-Version: 1.0
Class-Path:
Dependencies: org.hornetq
注意,(因为我为此苦苦挣扎了一段时间),该文件的解析非常“脆弱”。 “Class-Path:”输入行后面的空格至关重要。
I am trying to use JMS in a JBoss AS 7 application. Publishing normal messages seems to work OK, however when I try to use hornetq specific features (to exclude duplicate messages), an exception is thrown.
This is the code:
om.setStringProperty(org.hornetq.api.core.Message.HDR_DUPLICATE_DETECTION_ID.toString(), application+rs.getString("stream")+ rs.getInt("site"));
And here is the stack trace:
java.lang.ClassNotFoundException: org.hornetq.api.core.Message from [Module "deployment.TestRestEasy.war:main" from Service Module Loader]
org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:191)
org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:361)
org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:333)
org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:310)
org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:103)
sample.Processor.processStreamSite(Processor.java:82)
sample.Processor.processSitesForStream(Processor.java:63)
sample.Processor.process(Processor.java:55)
sample.HelloWorld.process(HelloWorld.java:31)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:140)
org.jboss.resteasy.core.ResourceMethod.invokeOnTarget(ResourceMethod.java:255)
org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:220)
org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:209)
org.jboss.resteasy.core.SynchronousDispatcher.getResponse(SynchronousDispatcher.java:519)
org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:496)
org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:119)
org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:208)
org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:55)
org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:50)
javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
I believe I have configured the standalone.xml configuration file correctly, as the standard JMS code works. Is there anything special I need to do to access HornetQ specific features?
Update:
Was worried was related to RestEasy stuff I was using, so moved into standalone Servlet, but still had same issue. Code and exception below
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try {
Context ic = new InitialContext();
QueueConnectionFactory qcf = (QueueConnectionFactory) ic.lookup("java:/ConnectionFactory");
Queue q = (Queue) ic.lookup("queue/test");
QueueConnection qc = qcf.createQueueConnection();
QueueSession qsess = qc.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
QueueSender qsend = qsess.createSender(q);
ObjectMessage om = qsess.createObjectMessage();
om.setObject((Serializable)new InboundDirectory("X", "Y", 9));
om.setStringProperty(org.hornetq.api.core.Message.HDR_DUPLICATE_DETECTION_ID.toString(), "X");
qsend.send(om);
System.out.println("X");
}
catch (Exception e) {
e.printStackTrace();
}
}
And here is the exception:
java.lang.ClassNotFoundException: org.hornetq.api.core.Message from [Module "deployment.TestRestEasy.war:main" from Service Module Loader]
org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:191)
org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:361)
org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:333)
org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:310)
org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:103)
TestServlet.doPost(TestServlet.java:65)
TestServlet.doGet(TestServlet.java:46)
javax.servlet.http.HttpServlet.service(HttpServlet.java:734)
javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
Further update:
Got it working by using the String value instead, but I don't think that is ideal, the property key is not guaranteed that string forever.
om.setStringProperty("_HQ_DUPL_ID", "X:Y:9");
Any idea the proper way to do it?
Update: Thanks @Vadzim for pointing me in the right direction. For anybody else struggling with this specific problem I updated the Manifest.MF as follows:
Manifest-Version: 1.0
Class-Path:
Dependencies: org.hornetq
Note, (as I struggled with this for a while), the parsing of this file is very 'fragile'. The Space after the 'Class-Path:' entry line is essential.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
JBoss 7 中的类加载模型发生了变化。它隐藏了许多未显式声明的内容。
您必须熟悉这些链接:
https://docs.jboss.org/author/display/AS7/Developer+Guide#DeveloperGuide-HowtoresolveClassNotFoundExceptionsandNoCLassDefFoundErrors
https://docs.jboss.org/author/display/AS7/Class+Loading+in+AS7
Classloading model changed in JBoss 7. It hides much stuff that's not explicitly declared.
You have to get familar with these links:
https://docs.jboss.org/author/display/AS7/Developer+Guide#DeveloperGuide-HowtoresolveClassNotFoundExceptionsandNoCLassDefFoundErrors
https://docs.jboss.org/author/display/AS7/Class+Loading+in+AS7
我相信 hornetq-client 应该暴露给 HOrnetQ 模块。
也许您应该通过他们的论坛与 AS7 人员交谈..或者也许在 jira.jboss.org 上提出 AS7 项目的问题..但我相信您需要首先在论坛上交谈。
I believe the hornetq-client should be exposed to the HOrnetQ module.
Maybe you should talk to AS7 guys through their forum.. or maybe raise an issue on jira.jboss.org for the AS7 project.. but I believe you are required to talk on the forums first.