Vertx尝试启动嵌入式服务器

时间:2021-09-28 18:02:50

I am trying to launch an initial test of a Vertx.io server, but I get the following error message:

我正在尝试启动Vertx.io服务器的初始测试,但是我收到以下错误消息:

Exception in thread "main" java.lang.NoClassDefFoundError: org/vertx/java/core/Handler

线程“main”中的异常java.lang.NoClassDefFoundError:org / vertx / java / core / Handler

Code:

package com.company;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.vertx.java.core.Handler;
import org.vertx.java.core.Vertx;
import org.vertx.java.core.VertxFactory;
import org.vertx.java.core.http.HttpServerRequest;

import java.io.IOException;

public class Main {
    private static final Logger log = LoggerFactory.getLogger(Main.class);
    private Object shutdownLock = new Object();

    public Main() throws IOException, InterruptedException {
        start(1234);
        keepServerFromShuttingDown();
    }

    private void keepServerFromShuttingDown() throws InterruptedException {
        synchronized (shutdownLock) {
            shutdownLock.wait();
        }
        log.info("Shutting down");
    }

    public void start(int port) {
        Vertx vertx = VertxFactory.newVertx();

        vertx.createHttpServer().requestHandler(new Handler<HttpServerRequest>() {

            @Override
            public void handle(HttpServerRequest request) {
            }
        }).listen(port);
    }

    public static void main(String[] args) throws IOException, InterruptedException {
        new Main();
    }
}

pom.xml:

<dependencies>
    <dependency>
        <groupId>io.vertx</groupId>
        <artifactId>vertx-core</artifactId>
        <version>2.1.2</version>
    </dependency>
    <dependency>
        <groupId>io.vertx</groupId>
        <artifactId>vertx-platform</artifactId>
        <version>2.1.2</version>
    </dependency>
    <dependency>
        <groupId>io.vertx</groupId>
        <artifactId>vertx-hazelcast</artifactId>
        <version>2.1.2</version>
    </dependency>
</dependencies>

1 个解决方案

#1


It looks like a basic CLASSPATH issue where it is not able to find Vertx classes while executing your program. Please check if the vertx libraries are indeed a part of your CLASSPATH.

它看起来像一个基本的CLASSPATH问题,它在执行程序时无法找到Vertx类。请检查vertx库是否确实是CLASSPATH的一部分。

Though unrelated, but if you are checking out Vertx for some new projects, I highly recommend version 3.0 and you could start with this simple maven project example

虽然不相关,但如果您要检查Vertx的某些新项目,我强烈推荐3.0版本,您可以从这个简单的maven项目示例开始

#1


It looks like a basic CLASSPATH issue where it is not able to find Vertx classes while executing your program. Please check if the vertx libraries are indeed a part of your CLASSPATH.

它看起来像一个基本的CLASSPATH问题,它在执行程序时无法找到Vertx类。请检查vertx库是否确实是CLASSPATH的一部分。

Though unrelated, but if you are checking out Vertx for some new projects, I highly recommend version 3.0 and you could start with this simple maven project example

虽然不相关,但如果您要检查Vertx的某些新项目,我强烈推荐3.0版本,您可以从这个简单的maven项目示例开始