1. 程式人生 > >Vert.x安裝指南

Vert.x安裝指南

官方安裝教程:http://vertx.io/install.html

安裝包下載地址:http://vertx.io/downloads.html

需要注意的是vertx至少需要JDK1.7版本

1、解壓安裝包

tar -zxvf ~/Downloads/vert.x-2.1.2.tar

2、新增環境變數

將vertx的bin目錄新增到PATH環境變數中

vi ~/.bash_profile

export VERTX_HOME=/usr/local/Cellar/vert.x-2.1.2
export PATH=$VERTX_HOME/bin:$PATH

source ~/.bash_profile 

3、檢查版本

vertx version

將會顯示vertx版本,類似如下:

2.1.2 (built 2014-07-24 07:45:28) 

4、測試安裝

我們可以通過寫一個簡單的web服務來測試vertx安裝

新建檔案server.js,新增下面的測試程式碼

var vertx = require('vertx');

vertx.createHttpServer().requestHandler(function(req) {
  req.response.end("Hello World!");
}).listen(8080, 'localhost');

執行程式碼:

vertx run server.js
首次執行vertx會從遠端下載依賴的模組
Downloading io.vertx~lang-rhino~2.1.1. Please wait... 
Downloading 100%
Module io.vertx~lang-rhino~2.1.1 successfully installed 
Downloading io.vertx~lang-js~1.1.0. Please wait... 
Downloading 100%
Module io.vertx~lang-js~1.1.0 successfully installed 
Succeeded in deploying verticle
開啟瀏覽器,輸入http://localhost:8080,你將會看到"Hello World!"