1

我正在尝试配置一个安装了插件的 activemq 代理,但似乎无法在代理配置文件中正确获取插件类的限定名称。我已经粘贴了错误消息,然后是下面的代理配置。基本上在元素中我指定 class="file:C:/Marcus/JavaProjects/Project/build/prod/classes/com/foo/jms/amqplugin/XmlValidationPlugin" 这是 XmlValidationPlugin.class 文件的绝对路径(有尝试将 .class 附加到上面的路径,但我得到了同样的错误)。最初我假设类属性应该指向 .class 文件,但尝试将其指向 .java 并且仍然无法正常工作。我已经阅读了关于开发插件、常见问题解答、spring 文档等的活动 MQ 常见问题解答。

我的类路径是 .;JAVA_HOME\lib;C:\Marcus\JavaProjects\Project;C:\Marcus\JavaProjects\Project\build\prod\classes 和 JAVA_HOME 是:C:\Program Files\Java\jdk1.7.0_03

所有 java 源代码都位于 C:\Marcus\JavaProjects\Project\src 中,.class 文件位于 C:\Marcus\JavaProjects\Project\build\prod\classes 中(类中的文件结构反映了 src 中的文件结构,例如com.foo.jms.amqplugin.XmlValidationPlugin 将在 classes/com/foo/jms/amqplugin 中拥有其 .class 文件)

有问题的插件是 XmlValidationPlugin.java,位于包中的文件夹 src 中:com.foo.jms.amqplugin

我曾尝试将 XmlValidationPlugin.class 放在 JAR 中并将 JAR 放在 activemqinstalldir/lib 中(正如向其他遇到类似问题的人所推荐的那样),但这并没有帮助。

我已经花了一天半的时间,如果有人知道 plugins 类属性的值应该是什么,我将不胜感激,因为我已经尝试了一切......提前致谢!

错误输出顶部:

C:\Program Files\apache-activemq-5.5.1>bin\activemq xbean:file:C:/Marcus/JavaProjects/Project/config/custom-broker.xml
Java Runtime: Oracle Corporation 1.7.0_03 C:\Program Files\Java\jdk1.7.0_03\jre
  Heap sizes: current=15872k  free=14246k  max=506816k
    JVM args: -Dcom.sun.management.jmxremote -Xmx512M -Dorg.apache.activemq.UseDedicatedTaskRunner=true -Djava.util.logging.config.file=logging.properties -Dactivemq.classpath=C:\Program Files\apache-
activemq-5.5.1\bin\../conf;C:\Program Files\apache-activemq-5.5.1\bin\../conf; -Dactivemq.home=C:\Program Files\apache-activemq-5.5.1\bin\.. -Dactivemq.base=C:\Program Files\apache-activemq-5.5.1\bin\
..
ACTIVEMQ_HOME: C:\Program Files\apache-activemq-5.5.1\bin\..
ACTIVEMQ_BASE: C:\Program Files\apache-activemq-5.5.1\bin\..
Loading message broker from: xbean:file:C:/Marcus/JavaProjects/Project/config/custom-broker.xml
 INFO | Refreshing org.apache.activemq.xbean.XBeanBrokerFactory$1@7a8ba4: startup date [Thu Apr 12 10:38:26 CEST 2012]; root of context hierarchy
ERROR: java.lang.RuntimeException: Failed to execute start task. Reason: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to load type: file:C:/Marcus/JavaProjects/Project/build/prod/classes/com/foo/jms/amqplugin/XmlValidationPlugin. Reason: java.lang.ClassNotFoundException: file:C:/Marcus/JavaProjects/Project/build/prod/classes/com/foo/jms/amqplugin/XmlValidationPlugin; nested exception is java.lang.ClassNotFoundException: file:C:/Marcus/JavaProjects/Project/build/prod/classes/com/foo/jms/amqplugin/XmlValidationPlugin
java.lang.RuntimeException: Failed to execute start task. Reason: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to load type: file:C:/Marcus/JavaProjects/Project/build/prod/classes/com/foo/jms/amqplugin/XmlValidationPlugin. 
Reason: java.lang.ClassNotFoundException: file:C:/Marcus/JavaProjects/Project/build/prod/classes/com/foo/jms/amqplugin/XmlValidationPlugin; nested exception is java.lang.ClassNotFoundException: file:C:/Marcus/JavaProjects/Project/build/prod/classes/com/foo/jms/amqplugin/XmlValidationPlugin
        at org.apache.activemq.console.command.StartCommand.runTask(StartCommand.java:98)
        at org.apache.activemq.console.command.AbstractCommand.execute(AbstractCommand.java:57)
        at org.apache.activemq.console.command.ShellCommand.runTask(ShellCommand.java:143)
        at org.apache.activemq.console.command.AbstractCommand.execute(AbstractCommand.java:57)
        at org.apache.activemq.console.command.ShellCommand.main(ShellCommand.java:85)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    ...

经纪人配置文件:

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:amq="http://activemq.apache.org/schema/core"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
  http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">

    <!-- Allows us to use system properties as variables in this configuration file -->
  <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
      <value>file:${activemq.base}/conf/credentials.properties</value>
    </property>
  </bean>

  <!--The <broker> element is used to configure the ActiveMQ broker. -->
  <broker xmlns="http://activemq.apache.org/schema/core" brokerName="localhost"
    dataDirectory="${activemq.base}/data">

        ...


    <!--plugin-->
    <plugins>
      <bean xmlns="http://www.springframework.org/schema/beans" 
            id="xmlValidationPlugin"  
            class="com.foo.jms.amqplugin.XmlValidationPlugin"/>
    </plugins>


  </broker>


</beans>
4

1 回答 1

1

基本上在元素中我指定 class="file:C:/Marcus/JavaProjects/Project/build/prod/classes/com/foo/jms/amqplugin/XmlValidationPlugin" 这是 XmlValidationPlugin.class 文件的绝对路径(有尝试将 .class 附加到上面的路径,但我得到了同样的错误)。最初我假设类属性应该指向 .class 文件,但尝试将其指向 .java 并且仍然无法正常工作。

您得到的错误似乎来自类加载器。

Reason: java.lang.ClassNotFoundException: file:C:/Marcus/JavaProjects/Project/build/prod/classes/com/foo/jms/amqplugin/XmlValidationPlugin; nested exception is java.lang.ClassNotFoundException: file:C:/Marcus/JavaProjects/Project/build/prod/classes/com/foo/jms/amqplugin/XmlValidationPlugin

类加载器需要一个完全限定的类名,而不是类文件的路径。尝试指定完全限定的类名而不是类文件的路径。

代替:

file:C:/Marcus/JavaProjects/Project/build/prod/classes/com/foo/jms/amqplugin/XmlValidationPlugin

采用:

com.foo.jms.amqplugin.XmlValidationPlugin

并确保 CLASSPATH 环境变量将包含:C:/Marcus/JavaProjects/Project/build/prod/classes

如果 ActiveMQ 使用一些自定义类加载器来加载插件(我不知道细节),您可能需要以一些 ActivemMQ 特定的方式指定类路径。

于 2012-04-12T10:10:07.843 回答