eclipseを使ってvert.xを起動する
Eclipseでvert.xをローカルで起動するのに、 Gradle テンプレートを使うってのは見かけたけどmavenプロジェクトの記事があまり見当たらなかったので覚え書き。
Eclipse Java EE IDE for Web Developers.Version: Juno Service Release 2
mavenはm2eプラグインを使用。
eclipseでmavenプロジェクトを作成して、Archetypeをvertxを選択する。
maven-dependency-plugin (goals “copy-dependencies”, “unpack”) is not supported by m2e
というpom.xmlのエラーが出るので
こちらの書き込みに従い
これでプロジェクトのエラーが消えるので、試しにfooパッケージに
package foo; import org.vertx.java.core.Handler; import org.vertx.java.core.http.HttpServerRequest; import org.vertx.java.platform.Verticle; public class HelloWorldVerticle extends Verticle { public void start() { container.logger().info("Verticle start."); vertx.createHttpServer().requestHandler(new Handler<HttpServerRequest>() { public void handle(HttpServerRequest req) { req.response().headers().set("Content-Type", "text/plain"); req.response().end("Hello World!"); } }).listen(8080); } }
というテストコードをServer.javaという名前で置いてみる。
さらに
src/main/resources/mod.jsonの
"main":"foo.PingVerticle",
を
"main":"foo.Server",
に変更する
eclipseのプロジェクトを右クリックRunからmaven buildで起動する。
※CLIの場合はmvn vertx:runModEclipseを叩く。
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". SLF4J: Defaulting to no-operation (NOP) logger implementation SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details. [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building Project - testio 0.0.1-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- vertx-maven-plugin:2.0.0-final:runModEclipse (default-cli) @ testio --- [INFO] CTRL-C to stop server
とかログが出るので,ブラウザからlocalhost:8080でhello worldが出ればおk