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?
Vert. x uses low level IO library Netty. The application framework includes these features: Polyglot.
As described in the Quarkus Reactive Architecture, Quarkus uses Vert. x underneath. Quarkus applications can access and use the Vert.
create a maven project as the manual says.
Then import the project as Maven project
Create a new launcher (Eclipse) using as main class
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:
And so forth.
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.
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.
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.
run org.example.InitVerticle -conf <path to config>
; where org.example.InitVerticle
is your main, or intialiser, verticle. 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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With