HiveMQ Prometheus 扩展 NoClassDefFoundError。无法启动扩展
HiveMQ Prometheus extension NoClassDefFoundError. Can't start extension
我是 运行 hivemq mqtt broker 社区版,想添加用于监控的 prometheus 扩展。
两者都是从 hivemq marketplace and the github project page.
预编译的
我将这两个组件下载为 zip 文件,解压缩并使用此 docker 文件将它们复制到 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[=11=](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
我也下载了 broker 和 extension 的源代码,并尝试用 maven/gradle 和 java 11 自己编译。但是结果完全一样。
代理运行没有任何错误。
有人知道这里出了什么问题吗?
实际上,hivemq broker 社区版中没有包含 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'],
编译代理后解压结果并将预编译的扩展添加到扩展目录。
错误消失,扩展程序似乎正常工作。
我是 运行 hivemq mqtt broker 社区版,想添加用于监控的 prometheus 扩展。
两者都是从 hivemq marketplace and the github project page.
预编译的
我将这两个组件下载为 zip 文件,解压缩并使用此 docker 文件将它们复制到 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[=11=](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
我也下载了 broker 和 extension 的源代码,并尝试用 maven/gradle 和 java 11 自己编译。但是结果完全一样。
代理运行没有任何错误。
有人知道这里出了什么问题吗?
实际上,hivemq broker 社区版中没有包含 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'],
编译代理后解压结果并将预编译的扩展添加到扩展目录。
错误消失,扩展程序似乎正常工作。