HiveMQ Prometheus扩展NoClassDefFoundError。无法开始扩展

时间:2019-07-24 13:42:09

标签: java docker mqtt prometheus hivemq

我正在运行hivemq mqtt经纪人社区版,并希望添加prometheus扩展以进行监视。
两者都是从hivemq marketplacegithub project page进行预编译的。
我将两个组件都下载为zip文件,解压缩它们,并使用以下dockerfile将它们复制到java 11 docker容器中:

FROM alpine:3.10  AS TOOLCHAIN
ADD https://github.com/hivemq/hivemq-community-edition/releases/download/2019.1/hivemq-ce-2019.1.zip /opt/
ADD https://www.hivemq.com/releases/extensions/hivemq-prometheus-extension-4.0.1.zip /opt/
WORKDIR /opt
RUN unzip hivemq-ce-* -d ./
RUN unzip hivemq-prometheus-extension* -d ./
RUN rm -rf hivemq-ce-*.zip
RUN rm -rf hivemq-prometheus-extension*.zip
RUN mv ./hivemq-ce-* ./hivemq

FROM openjdk:11-jdk-slim
COPY --from=TOOLCHAIN /opt/hivemq /opt/hivemq
COPY --from=TOOLCHAIN /opt/hivemq-prometheus-extension /opt/hivemq/extensions/hivemq-prometheus-extension
WORKDIR /opt/hivemq/
CMD ["chmod","755","./bin/run.sh"]
CMD ["./bin/run.sh"]

我认为我已经从正确的步骤中走了出来,但是当我使用docker build -t hive-test .; docker run -p 1883:1883 -p 9399:9399 -t hive-test启动容器时,我得到了一个错误。

2019-07-24 13:19:57,125 INFO  - Starting HiveMQ Community Edition Server
2019-07-24 13:19:57,127 INFO  - HiveMQ version: 2019.1
2019-07-24 13:19:57,127 INFO  - HiveMQ home directory: /opt/hivemq
2019-07-24 13:19:57,162 INFO  - Log Configuration was overridden by /opt/hivemq/conf/logback.xml
2019-07-24 13:19:57,356 INFO  - This HiveMQ ID is mwDbQ
2019-07-24 13:20:14,353 INFO  - Created user preferences directory.
2019-07-24 13:20:14,873 INFO  - Starting HiveMQ extension system.
2019-07-24 13:20:14,925 INFO  - Starting TCP listener on address 0.0.0.0 and port 1883
2019-07-24 13:20:14,998 INFO  - Started TCP Listener on address 0.0.0.0 and on port 1883
2019-07-24 13:20:14,999 INFO  - Started HiveMQ in 17877ms
2019-07-24 13:20:15,040 ERROR - Extension with id "hivemq-prometheus-extension" cannot be started because of an uncaught exception thrown by the extension. Extension will be disabled.
java.lang.NoClassDefFoundError: javax/servlet/ServletContextListener
        at org.eclipse.jetty.server.handler.ContextHandler.<clinit>(ContextHandler.java:114)
        at com.hivemq.extensions.prometheus.export.PrometheusServer.start(PrometheusServer.java:64)
        at com.hivemq.extensions.prometheus.PrometheusMainClass.extensionStart(PrometheusMainClass.java:65)
        at com.hivemq.extensions.HiveMQExtensionImpl.start(HiveMQExtensionImpl.java:133)
        at com.hivemq.extensions.HiveMQPlugins.pluginStart(HiveMQPlugins.java:209)
        at com.hivemq.extensions.loader.PluginLifecycleHandlerImpl.lambda$startPlugin$0(PluginLifecycleHandlerImpl.java:82)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
        at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.ClassNotFoundException: javax.servlet.ServletContextListener
        at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:471)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:588)
        at com.hivemq.extensions.classloader.IsolatedPluginClassloader.loadClass(IsolatedPluginClassloader.java:123)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
        ... 9 common frames omitted

我还下载了代理和扩展源代码,并尝试使用maven / gradle和java 11对其进行编译。但是结果完全相同。

代理运行没有任何错误。

有人知道这里出了什么问题吗?

1 个答案:

答案 0 :(得分:0)

实际上,hivemq代理社区版中没有任何依赖包含 ServletContextListener 。我从github下载了源代码,并修改了 build.gradle 文件。

将以下代码片段的最后一行添加到build.gradle文件中:

/* javax */
[group: 'javax.activation', name: 'activation', version: '1.1.1'],
[group: 'javax.validation', name: 'validation-api', version: '1.1.0.Final'],
[group: 'javax.annotation', name: 'javax.annotation-api', version: '1.3.2'],
[group: 'javax.servlet', name: 'javax.servlet-api', version: '4.0.1'],

编译代理后,将结果解压缩并将预编译的扩展名添加到扩展目录中。

错误消失了,扩展程序似乎可以正常工作。