我已经下载并运行了 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 中对其进行编译?如果没有,我需要做什么才能使其正常工作?