如何在Eclipse中运行Vert.x应用

Vert.x是一个在JVM上构建响应式应用的工具集(toolkit),在性能上十分出众。本文探讨了如何在Eclipse上运行基于Vert.x框架的应用。

在本例中,Vert.x的版本为3.4.2,JDK版本1.8,Kotlin版本1.1.2。

1、创建Maven工程

 点击完成时会发现pom.xml报错,这时右键该工程,选择Java EE tools-->Generate Deployment Descriptor Stub即可消除报错。

2、添加对Vert.x的支持

在maven中引入vert.x的core包

  <dependencies>
    <dependency>
        <groupId>io.vertx</groupId>
        <artifactId>vertx-core</artifactId>
        <version>3.4.2</version>
    </dependency>
  </dependencies> 

使用Kotlin编写一个简单的Vert.x服务

package com.example.vertx

import io.vertx.core.AbstractVerticle

class MyServer : AbstractVerticle() {
    override fun start() {
        vertx.createHttpServer()
            .requestHandler() { req ->
                req.response().putHeader("content-type", "text/plain")
                    .end("My first Vert.x server.")
            }
        .listen(8082)
    }
}

 开始运行该服务,右键工程,Run As-->Java Application,在弹出提示框中选择io.vertx.core.Launcher左右工程的Main Class。

点击Ok后会发现并没有执行成功,提示信息是

Usage: java io.vertx.core.Launcher [COMMAND] [OPTIONS] [arg...]

Commands:
    bare      Creates a bare instance of vert.x.
    list      List vert.x applications
    run       Runs a verticle called <main-verticle> in its own instance of
              vert.x.
    start     Start a vert.x application in background
    stop      Stop a vert.x application
    version   Displays the version.

Run 'java io.vertx.core.Launcher COMMAND --help' for more information on a command.

还需要将入口类配置到运行的参数中。右键工程,Run As-->Run Configuration...,选择Arguments选项卡中添加Program Arguments。

加入的参数 run com.example.vertx.MyServer,即刚编写的Vert.x服务类。

再次运行,显示运行成功。

六月 23, 2017 4:44:54 下午 io.vertx.core.impl.launcher.commands.VertxIsolatedDeployer
信息: Succeeded in deploying verticle

3、验证服务

在浏览器中打开http://localhost:8082/

服务运行正常。

 

本次介绍了使用Vert.x搭建最简单的WEB服务,更复杂的服务还需要引入vertx-web等jar包。

 

posted on 2017-06-23 16:55  仙人抚顶 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/rexSky/p/7070174.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值