1:在src/conf目錄下建立conf.jsonjava
{ "http.port" : 8082 }
2:建立Verticle,json
config().getInteger("http.port", 8080),將會讀取配置文件,是否有http.port,沒有就使用8080做爲默認,
package verticleTest; import io.vertx.core.AbstractVerticle; import io.vertx.core.Future; public class ConfigVerticle extends AbstractVerticle{ public void start(Future<Void> fut) { vertx .createHttpServer() .requestHandler(r -> { r.response().end("<h1>Hello from my first " + "Vert.x 3 application</h1>"); }) .listen( // Retrieve the port from the configuration, // default to 8080. config().getInteger("http.port", 8080), result -> { if (result.succeeded()) { fut.complete(); } else { fut.fail(result.cause()); } } ); } }
3:打包,發佈。使用 -conf 將配置文件讀入。app
D:\Android\workspace1\Ali>java -jar target/Ali-0.0.1-SNAPSHOT-fat.jar -conf src/main/conf/conf.jsonspa
4:訪問localhost:8082code