在JBoss中引用hornetq特定内容的ClassNotFoundException为7。

时间:2020-12-05 20:51:22

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:

我尝试在JBoss中使用JMS作为7个应用程序。发布正常消息似乎没问题,但是当我尝试使用hornetq特定的特性(排除重复消息)时,抛出一个异常。这是代码:

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?

我相信我已经配置了独立的。正确的xml配置文件,作为标准的JMS代码工作。我需要做什么特别的事情来访问HornetQ的特性吗?

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

更新:担心与我正在使用的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();
  }
}

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:

更新:感谢@Vadzim指向正确的方向。对于其他与这个特定问题纠结的人,我更新了清单。MF如下:

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.

注意,(当我在这个过程中挣扎了一段时间),这个文件的解析非常“脆弱”。在“类路径”之后的空间是至关重要的。

2 个解决方案

#1


4  

Classloading model changed in JBoss 7. It hides much stuff that's not explicitly declared.

在JBoss 7中,类加载模型发生了变化。它隐藏了很多未明确声明的内容。

You have to get familar with these links:

你必须熟悉这些链接:

https://docs.jboss.org/author/display/AS7/Developer+Guide#DeveloperGuide-HowtoresolveClassNotFoundExceptionsandNoCLassDefFoundErrors

# DeveloperGuide-HowtoresolveClassNotFoundExceptionsandNoCLassDefFoundErrors https://docs.jboss.org/author/display/AS7/Developer +指南

https://docs.jboss.org/author/display/AS7/Class+Loading+in+AS7

加载https://docs.jboss.org/author/display/AS7/Class + +在+ AS7

#2


1  

I believe the hornetq-client should be exposed to the HOrnetQ module.

我相信HOrnetQ -client应该暴露在HOrnetQ模块中。

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.

也许你应该通过他们的论坛和AS7的人谈谈。或者在jira.jboss.org上为AS7项目提出一个问题。但我相信你必须先在论坛上发言。

#1


4  

Classloading model changed in JBoss 7. It hides much stuff that's not explicitly declared.

在JBoss 7中,类加载模型发生了变化。它隐藏了很多未明确声明的内容。

You have to get familar with these links:

你必须熟悉这些链接:

https://docs.jboss.org/author/display/AS7/Developer+Guide#DeveloperGuide-HowtoresolveClassNotFoundExceptionsandNoCLassDefFoundErrors

# DeveloperGuide-HowtoresolveClassNotFoundExceptionsandNoCLassDefFoundErrors https://docs.jboss.org/author/display/AS7/Developer +指南

https://docs.jboss.org/author/display/AS7/Class+Loading+in+AS7

加载https://docs.jboss.org/author/display/AS7/Class + +在+ AS7

#2


1  

I believe the hornetq-client should be exposed to the HOrnetQ module.

我相信HOrnetQ -client应该暴露在HOrnetQ模块中。

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.

也许你应该通过他们的论坛和AS7的人谈谈。或者在jira.jboss.org上为AS7项目提出一个问题。但我相信你必须先在论坛上发言。