Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run Vertx in an IDE

Is there any way to run Vertx from within an IDE? I know I can create a server in a file and then call

vertx run server.java

from the command line, but is there a way to run the server.java file from within an IDE?

like image 349
j will Avatar asked Jun 18 '14 04:06

j will


People also ask

Does Vertx use Netty?

Vert. x uses low level IO library Netty. The application framework includes these features: Polyglot.

Is Quarkus using Vertx?

As described in the Quarkus Reactive Architecture, Quarkus uses Vert. x underneath. Quarkus applications can access and use the Vert.


4 Answers

  • create a maven project as the manual says.

  • Then import the project as Maven project

  • Create a new launcher (Eclipse) using as main class

    • For Vert.x 2.x: "org.vertx.java.platform.impl.cli.Starter"
    • For Vert.x 3.x: "io.vertx.core.Starter"
  • In the tab "Program Arguments" type: "run your.package.ServerVerticle -conf conf.json"

You can omit the conf.json if you don't have one, it's just an example to show you that you can put there any other option you'd put launching Vert.x from the command line.

PRO TIP: if your verticle is written in another language, use the prefix with the name of the language as follows:

  • "run scala:com.acme.MainVerticle -conf conf.json"
  • "run jython:MainVerticle.py -conf conf.json"
  • "run jruby:MainVerticle.rb -conf conf.json"
  • "run rhino:MainVerticle.js -conf conf.json"
  • "run groovy:MainVerticle.groovy -conf conf.json"

And so forth.

like image 136
sscarduzio Avatar answered Oct 31 '22 17:10

sscarduzio


The accepted answer is perfectly fine. Just for completness's sake, you also simply can run a plain old java main class, having a the main start your vertx instance.

Code should be something like:

public static void main(final String... args) {
    Vertx vertx = Vertx.vertx();
    vertx.deployVerticle(/* put your stuff here */);
}

There you go.

like image 31
Psyx Avatar answered Oct 31 '22 18:10

Psyx


Vert.x 3

I previously edited an earlier answer, but I'm separating it out for the sakes of clarity.

The example below is for eclipse, but the same basic premise should work with any IDE.

Setup

  • Set up your Maven, Gradle, or other project and import it into Eclipse

  • Create a run or debug config, and set io.vertx.core.Launcher as your main class.

  • In the arguments tab, set the program arguments: run org.example.InitVerticle -conf <path to config>; where org.example.InitVerticle is your main, or intialiser, verticle.

Debugging

During debugging in Vert.x 3 you may notice that a blocked thread watchdog continually outputs warnings (and, eventually, exceptions) onto the console. Whilst useful during production, you can inhibit this behaviour by setting the following property in VM arguments of your debug config:

-Dvertx.options.blockedThreadCheckInterval=2147483647
Caveats

Be aware that your debugging is liable to trigger timeouts in a variety of scenarios, such as a breakpoint delaying a reply on the eventbus. You'll see warnings like:

WARNING: Message reply handler timed out as no reply was received - it will be removed

Clearly, this could mean different control flows under debugging than real execution if you aren't careful.

like image 35
Marc Savy Avatar answered Oct 31 '22 16:10

Marc Savy


I would suggest what Fran already hinted at. Best you create your Maven project from the archetype (http://vertx.io/maven_dev.html) such as

mvn archetype:generate -Dfilter=io.vertx: -DgroupId=your.group.id -DartifactId=your-artifact -Dversion=0.0.1-SNAPSHOT

and add the IDE specifics via maven, for example for Eclipse

mvn eclipse:eclipse

By that you have an ready to import and ready to use project in Eclipse.

To actually start it then, I wouldn't go directly for a Main or Starter Verticle as but just simple run it through Maven in Eclipse as new Run Configuration. Create a new Maven Run Configuration and set as goals

clean compile vertx:runMod

It will start the mod.json configured "Main" class.

Note: clean compile is not necessary, but if you build it once and have installed jars of your project running around, the auto-deploy doesn't work anymore as it picks the build instead of the developed code.

Like that you have the example PingVerticle directly running and can also fool around as auto-redeploy is enabled in the mod.json.

If you then need more, configs etc. you can work with Starter Verticles, the parameters or even add it to the pom.xml vertx-maven-plugin.

I hope this helps.

Best

like image 30
INsanityDesign Avatar answered Oct 31 '22 17:10

INsanityDesign