Run Vertx in an IDE

20,261

Solution 1

  • 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.

Solution 2

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.

Solution 3

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.

Solution 4

My setting below is done at IntelliJ 15.0.1 with vert.x 3.2.0 for Java

  1. download and extract vertx library (http://vertx.io/download/) to somewhere
  2. at IntelliJ, 'New Project' -> select Java and Project SDK 1.8 -> Next
  3. check 'Create project from template' and 'Command Line App' -> Next
  4. input 'Project Name' you want -> Finish
  5. 'File' -> 'Project Structure...' -> select 'Libraries'
  6. '+'(New Project Library) -> 'Java' -> add (somewhere)/vert.x-3.2.0-full/lib -> 'OK'
  7. add New Verticle like :

    public class HiVerticle extends AbstractVerticle {
    @Override
    public void start() throws Exception {
        super.start();
        System.out.println("Hi");
    }}
    
  8. 'Run' -> 'Edit Configurations...' -> replace 'Main class:' to 'io.vertx.core.Launcher',

    input 'run cchcc.hi.HiVerticle' at 'Program arguments:' -> 'OK'

  9. Run and Debug!

result

Solution 5

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

Share:
20,261
j will
Author by

j will

Updated on July 23, 2022

Comments

  • j will
    j will almost 2 years

    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?