如何解决错误:java.lang.ClassNotFoundException:io.netty.util.concurrent.GenericFutureListener?

时间:2018-10-04 21:36:31

标签: java prometheus

昨天,我第一次尝试用Java制作Prometheus Client(不是从Python开始,最后是GoLang)。

找到示例

import io.prometheus.client.Counter;
import io.prometheus.client.Gauge;
import io.prometheus.client.Histogram;
import io.prometheus.client.Summary;
import io.prometheus.client.vertx.MetricsHandler;
import io.vertx.core.Vertx;
import io.vertx.ext.web.Router;
//import io.prometheus.client.vertx.MetricsHandler;

public class ExampleExporter {

    static final Gauge g = Gauge.build().name("gauge").help("blah").register();
    static final Counter c = Counter.build().name("counter").help("meh").register();
    static final Summary s = Summary.build().name("summary").help("meh").register();
    static final Histogram h = Histogram.build().name("histogram").help("meh").register();
    static final Gauge l = Gauge.build().name("labels").help("blah").labelNames("l").register();

    public static  void main(String[] args) throws Exception {
        final Vertx vertx = Vertx.vertx();
        final Router router = Router.router(vertx);

        router.route("/metrics").handler(new MetricsHandler());

        vertx.createHttpServer().requestHandler(router::accept).listen(8001);

        g.set(1);
        c.inc(2);
        s.observe(3);
        h.observe(4);
        l.labels("foo").inc(5);
    }



}

已从Maven库加载。

尝试运行客户端后,返回错误:

Exception in thread "main" java.lang.NoClassDefFoundError: io/netty/util/concurrent/GenericFutureListener
    at io.vertx.core.impl.VertxFactoryImpl.vertx(VertxFactoryImpl.java:30)
    at io.vertx.core.Vertx.vertx(Vertx.java:78)
    at ExampleExporter.main(ExampleExporter.java:22)
Caused by: java.lang.ClassNotFoundException: io.netty.util.concurrent.GenericFutureListener
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 3 more

所有代码和lib均已上传 Git Repository

请帮助解决此问题。

1 个答案:

答案 0 :(得分:0)

好像您缺少依赖项。您可以从

获得

https://mvnrepository.com/artifact/io.netty/netty-all/5.0.0.Alpha2

您可以添加

<!-- https://mvnrepository.com/artifact/io.netty/netty-all -->
<dependency>
    <groupId>io.netty</groupId>
    <artifactId>netty-all</artifactId>
    <version>5.0.0.Alpha2</version>
</dependency>

到您的pom文件或从站点下载jar,然后将其添加到类路径或您的lib文件夹中。