2

我已经下载并运行了 Vertx,但是当我编辑其中一个示例以开始使用 Java 8 功能 (lambdas) 时,我不断收到编译器错误。在 Intellij 中,一切都编译得很好,并且 IntelliJ 指向我的 Java 8 JDK,但是当我从命令行运行 Vertx 时,会出现编译错误:

> vertx run FanoutServer.java
C:\Users\i50640\Documents\Intellij Projects\EchoServer\src\main\java\echoserver\FanoutServer.java:33: error: illegal start of expression
        vertx.createNetServer().connectHandler(socket -> {
                                                       ^
C:\Users\i50640\Documents\Intellij Projects\EchoServer\src\main\java\echoserver\FanoutServer.java:33: error: illegal start of expression
        vertx.createNetServer().connectHandler(socket -> {
                                                         ^
C:\Users\i50640\Documents\Intellij Projects\EchoServer\src\main\java\echoserver\FanoutServer.java:33: error: ';' expected
        vertx.createNetServer().connectHandler(socket -> {
                                                          ^
C:\Users\i50640\Documents\Intellij Projects\EchoServer\src\main\java\echoserver\FanoutServer.java:34: error: illegal start of expression
            connections.add(socket.writeHandlerID());
Failed in deploying verticle
java.lang.RuntimeException: Compilation failed
    at org.vertx.java.platform.impl.java.CompilingClassLoader.<init>(CompilingClassLoader.java:108)
    at org.vertx.java.platform.impl.java.JavaVerticleFactory.createVerticle(JavaVerticleFactory.java:51)
    at org.vertx.java.platform.impl.DefaultPlatformManager$21.run(DefaultPlatformManager.java:1723)
    at org.vertx.java.core.impl.DefaultContext$3.run(DefaultContext.java:175)
    at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:370)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:353)
    at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:116)
    at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.RuntimeException: Compilation failed!
    at org.vertx.java.platform.impl.java.CompilingClassLoader.<init>(CompilingClassLoader.java:105)
    ... 7 more

Failed in deploying verticle
java.lang.RuntimeException: Compilation failed
    at org.vertx.java.platform.impl.java.CompilingClassLoader.<init>(CompilingClassLoader.java:108)
    at org.vertx.java.platform.impl.java.JavaVerticleFactory.createVerticle(JavaVerticleFactory.java:51)
    at org.vertx.java.platform.impl.DefaultPlatformManager$21.run(DefaultPlatformManager.java:1723)
    at org.vertx.java.core.impl.DefaultContext$3.run(DefaultContext.java:175)
    at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:370)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:353)
    at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:116)
    at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.RuntimeException: Compilation failed!
    at org.vertx.java.platform.impl.java.CompilingClassLoader.<init>(CompilingClassLoader.java:105)
    ... 7 more

这是 FanoutServer.java 文件:

public class FanoutServer extends Verticle {

    public void start()  {
        final Set<String> connections = vertx.sharedData().getSet("conns");

        vertx.createNetServer().connectHandler(socket -> {
            connections.add(socket.writeHandlerID());
            socket.dataHandler(buffer -> {
                for (String actorID : connections) {
                    vertx.eventBus().publish(actorID, buffer);
                }
            });
            socket.closeHandler(new VoidHandler() {
                public void handle() {
                    connections.remove(socket.writeHandlerID());
                }
            });
        }).listen(6748);
    }
}

在能够使用 Java 8 功能之前,我是否需要下载 Vertx 源代码并在 Java 8 中对其进行编译?如果没有,我需要做什么才能使其正常工作?

4

2 回答 2

3

检查您的JAVA_HOME环境变量并确保它也指向正确的jdk.

于 2014-06-18T22:01:52.563 回答
2

答案可在 Vertx 的 google 组中找到:

https://groups.google.com/forum/#!topic/vertx/pG7mIo3-03o

简而言之,我的 Windows 机器上的 JAVA_HOME 变量指向 JDK 1.7 而不是 1.8。

于 2014-06-18T22:25:34.177 回答