Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to start Vert.x server from IntelliJ IDEA?

How do I start a simple Vert.x server from inside IntelliJ IDEA?

My build.gradle is as below:

apply plugin: 'java'  version = '3.0.0'  repositories {     mavenCentral() }  dependencies {     compile 'io.vertx:vertx-core:3.0.0' } 

My Vertx-server, MyVertex.java is as below:

package com.example;  import io.vertx.core.AbstractVerticle; import io.vertx.core.Future;  public class MyVerticle extends AbstractVerticle {      @Override     public void start(Future<Void> fut) {         vertx.createHttpServer()                 .requestHandler(r -> r.response().end("<h1>Hello</h1>"))                 .listen(8081);     } } 

And my IntelliJ run configuration is as below, with io.vertx.core.Starteras main class: enter image description here

But when I run it with my run configuration I get this error message:

Error: Could not find or load main class run 

Is the VM option (in Run configuration) run something I need to install and add to my path or how do I get started with Vert.x-server development?

like image 661
Jonas Avatar asked Aug 25 '15 13:08

Jonas


People also ask

What is Vert X used for?

x website (vertx.io) says, “Eclipse Vert. x is a toolkit for building reactive applications on the JVM.” It is event-driven, single-threaded, and non-blocking, which means you can handle many concurrent apps with a small number of threads. (If you know how the Node. js event loop works, Vert.


2 Answers

I'm using vertx 3.2.1 and it's complaining about io.vertx.core.Starter. It's deprecated now. So, one should use io.vertx.core.Launcher.

This is an example of launching via intellij with the option of specifying a config JSON file:

  • Main Class: io.vertx.core.Launcher
  • VM Options: <up to you, or leave blank>
  • Program Arguments: run com.app.verticle.MyVerticle -conf /path/to/my_config.json

When using a logging framework it will be added in VM Options as below.

Log4j with either log4j or slf4j delgate:

-Dvertx.logger-delegate-factory-class-name=io.vertx.core.logging.Log4jLogDelegateFactory -Dlog4j.configuration=log4j.xml  -Dvertx.logger-delegate-factory-class-name=io.vertx.core.logging.SLF4JLogDelegateFactory -Dlog4j.configuration=log4j.xml 

Logback:

-Dvertx.logger-delegate-factory-class-name=io.vertx.core.logging.SLF4JLogDelegateFactory -Dlogback.configurationFile=logback.xml 
like image 134
corindiano Avatar answered Sep 19 '22 10:09

corindiano


Simply add this to your MyVerticle (or a separate class):

import io.vertx.core.Launcher; ... public static void main(final String[] args) {     Launcher.executeCommand("run", MyVerticle.class.getName()); } 

Then simply Ctrl+Shift+F10 to run it and IntelliJ will automatically create the Run Configuration.

like image 41
Jared Avatar answered Sep 20 '22 10:09

Jared