Vertx尝试启动嵌入式服务器

时间:2015-05-13 12:19:05

标签: java maven pom.xml vert.x

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

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

代码:

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 个答案:

答案 0 :(得分:1)

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

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